Solved

URL Grabber

Posted on 2002-05-10
7
290 Views
Last Modified: 2010-03-31
hi,

i've the following code snippet to grab the return URL of another site:
--------------------------
urlRemote = new URL(strURL);              
in = new BufferedReader(
new InputStreamReader(urlRemote.openStream()));
while ( (strLine = in.readLine() ) != null )
{
     vecReturn.add(strLine);
}
in.close();

---------------------------
when i reach the above piece of codes, i was thrown the java.io.FileNotFoundException.

can someone tell me what could possibly be wrong?
thanks.
0
Comment
Question by:osiruz
  • 4
  • 3
7 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 7000683
 Well it is obvious that it cannot find the file. Are you sure that the file you are trying to access exists?
0
 

Author Comment

by:osiruz
ID: 7000849
im not familiar with this url grabber thing..
i do not understand the above code fully,
can someone help ? If i were to grab a particular URL response from another site, how can this be achieve?
0
 
LVL 35

Accepted Solution

by:
girionis earned 50 total points
ID: 7000885
 The URL class represents exactly this: a url that points to a resource on the Internet. You cannot use it to read a response from a server but rather you can read files, directories, database queries etc. Maybe this will help you: http://java.sun.com/products/jdk/1.2/docs/api/java/net/URL.html

> If i were to grab a particular URL response from another site, how can this be achieve?

 What exactly do you mean by this? Do you want to connect to a server and read the response back (using Sockets) or you would like to do server-side processing (using Servlets/JSP)?

>urlRemote = new URL(strURL);

  You create a new URL object by passing a String representation of the url. String could be anything like: http://www.yahoo.com
             
>in = new BufferedReader(new InputStreamReader(urlRemote.openStream()));

  Once the url object is created you open a connection to the url and you get an InputStream for reading from this url.

>while ( (strLine = in.readLine() ) != null )
>{
>    vecReturn.add(strLine);
>}

  While there is data coming from this url then you append everything in a collection object (Vector).

>in.close();

  You close the stream fro reading from the url.

  Hope it helps.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

 

Author Comment

by:osiruz
ID: 7000931
im not familiar with this url grabber thing..
i do not understand the above code fully,
can someone help ? If i were to grab a particular URL response from another site, how can this be achieve?
0
 

Author Comment

by:osiruz
ID: 7000936
thanks..i'll need some time to digest that.
thanks again for the response.
0
 

Author Comment

by:osiruz
ID: 7065483
Thanks for the help.
0
 
LVL 35

Expert Comment

by:girionis
ID: 7065503
 Not at all. I am glad I helped. :-)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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
type mismatch (Object[] to double[] 4 33
servlet example 17 51
maven module vs maven project 3 46
Fast way to search item into Java Array (Rhino compatible) 2 31
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

860 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