Solved

URL Grabber

Posted on 2002-05-10
7
265 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

867 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now