aspose file tools*
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 Spring in Action this week in the Spring 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: 19720
    
  20

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creation of .txt file from contents of a URL