This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Sockets and Internet Protocols and the fly likes redirecting the response stream to a file Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Reply Bookmark "redirecting the response stream to a file" Watch "redirecting the response stream to a file" New topic
Author

redirecting the response stream to a file

William Stafford
Ranch Hand

Joined: Dec 13, 2004
Posts: 109
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

Joined: Oct 27, 2005
Posts: 19216

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.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: redirecting the response stream to a file
 
Similar Threads
Sound in servlet output stream
How to refer a html using file system path in an html which is deployed in war file?
Giving a URL for File
Information on Streaming
pass a file from a server to another using servlets or ?!.