Solved

URL Grabber

Posted on 2002-05-10
7
301 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
[X]
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
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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
check java version using powershell 13 304
Is Applet the way to go for my drag and drop system? 8 35
web project error add remove 1 55
program arguments vs VM arguments 4 31
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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 will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

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