• Post Reply Bookmark Topic Watch Topic
  • New Topic

Creation of .txt file from contents of a URL

 
Dhee raj
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Saloon Keeper
Posts: 3333
61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20831
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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().
 
my overalls have superpowers - they repel people who think fashion is important. Tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!