Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 326
  • Last Modified:

URL Grabber

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
osiruz
Asked:
osiruz
  • 4
  • 3
1 Solution
 
girionisCommented:
 Well it is obvious that it cannot find the file. Are you sure that the file you are trying to access exists?
0
 
osiruzAuthor Commented:
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
 
girionisCommented:
 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
osiruzAuthor Commented:
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
 
osiruzAuthor Commented:
thanks..i'll need some time to digest that.
thanks again for the response.
0
 
osiruzAuthor Commented:
Thanks for the help.
0
 
girionisCommented:
 Not at all. I am glad I helped. :-)
0

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.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now