• Post Reply Bookmark Topic Watch Topic
  • New Topic

redirecting the response stream to a file  RSS feed

 
William Stafford
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to send a request to a web service and write the response to a file. I can sort of imagine how to do this if the response is a stream but I would think there must be a more compact way.

Can anyone suggest a way or point me to an example.

Thanks,
-=beeky
 
Rob Spoor
Sheriff
Posts: 21095
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nope, using streams is the way to go. With URL and URLConnection, you can only access the web page through a stream. You may be able to use a Channel instead, but in essence it's almost the same thing: copy content from the source (URLConnection's getInputStream() or a Channel) to the destination (a FileOutputStream or a FileChannel).

Since there is no direct way to get a Channel from the URLConnection's OutputStream (Channels.newChannel does not count - it simply wraps the OutputStream) that leaves one option.

Now of course you could use a third party library like Apache's HttpClient, but in the end it's all the same.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!