How to read a URL content ???

Posted on 2000-04-10
Last Modified: 2009-12-16
Hi all,
I wanna know how to read content of a URL page from applet ???


Question by:joely
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

dmaguillo earned 80 total points
ID: 2699553
Ho joely.

Here u have an example function that obtain content from an URL page:

    public static StringBuffer getURLContent (String url) {
        StringBuffer sb = new StringBuffer ();
        URL URLcontent = new URL(url);
        URLConnection conn = null;
        BufferedReader data = null;

        try {
            conn = URLcontent.openConnection();
            data = new BufferedReader (
                       new InputStreamReader (
                           conn.getInputStream ()));
        catch (IOException e) {
            System.out.println("Problems opening URL");

        boolean test = true;
        while (test)
            String str;
            try {
                str = new String (data.readLine ());
            catch (Throwable e) { str = null; }
            if (str != null)
                sb.append (str);
                sb.append ('\n');
                str = null;
            else { test = false; }
        return sb;

Bye... :)

Author Comment

ID: 2702841
Thank u so much dmaguillo.
How if I want use that function in servlet. I always get problem in opening URL.


Expert Comment

ID: 2706482
hai joely,
  Check  whether u have give correct url,
  ie. in server side u  use these function to get url,
 URL url=new URL(req.getScheme()+"://"+req.getServerName()+":"+req.getServerPort()+"/file path");

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Chrome and Firefox Java 5 69
printf performancy 11 86
Why doesn't this text field show up on my Applet frame? 2 28
How to configure empty element in XML Document parser? 15 45
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to implement Singleton Design Pattern in Java.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question