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.
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.
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().