This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Creation of .txt file from contents of a URL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Creation of .txt file from contents of a URL" Watch "Creation of .txt file from contents of a URL" New topic
Author

Creation of .txt file from contents of a URL

Dhee raj
Greenhorn

Joined: Sep 13, 2011
Posts: 4
Hi all,
I wanted to write a method that takes in a URL and creates a .txt file
(containing the text part present in the page).It should also create
text files from all the links present in the main URL.Wanted to know
the best way to achieve this.

Thanks in advance.
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
The easiest might be to use new URL("...").getContent() which returns an InputStream, the contents of which you can then save to a file via FileOutputStream.

Extracting links and treating them similarly is tougher. I'd use a library like HtmlUnit for that.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19656
    
  18

Tim Moores wrote:The easiest might be to use new URL("...").getContent() which returns an InputStream

It actually returns an Object which may or may not be an InputStream. The proper way is to use new URL("...").openStream() which is shorthand for new URL("...").openConnection().getInputStream().


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Creation of .txt file from contents of a URL
 
Similar Threads
Array dimension missing
Comparing two huge files
and after SEARCH for a any string like words or sentence or urls, for how many times appeared on pag
compiler error
problem with insert and select