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
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply 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: 2407
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: 19232

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
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Creation of .txt file from contents of a URL
 
Similar Threads
compiler error
problem with insert and select
and after SEARCH for a any string like words or sentence or urls, for how many times appeared on pag
Array dimension missing
Comparing two huge files