This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to Stream Files from Application Server  RSS feed

 
Sajit Jana
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I would like to know , how do I go about in streaming/downloading files from the applicatin server to the client system.
thanks
sajit
 
Charles Lyons
Author
Ranch Hand
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's a four-step process to downloading files from a networked environment (inc. the Internet):
  • Create a java.net.URL object with the appropriate source file as the URL specified
  • Obtain an InputStream from your URL object, from the openStream() method
  • Create an output file (if required) and an OutputStream
  • Read bytes from the InputStream of the source file, and write to the OutputStream of the destination file

  • A download procedure is much better run in a separate thread, or it will hold up other computations that you wish to take place at the same time. The example below achieves this.
    This is a sample of what you would be looking at for a single "Downloader" class:

    That should work, but there are more sophisticated solutions if you need to download multiple files - you could have them in sequential download, for example, or downloading simultaneously; I leave that experimentation to you! Good luck.
    [ June 06, 2003: Message edited by: Charles Lyons ]
     
    Sajit Jana
    Greenhorn
    Posts: 3
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi,
    Thanks for the reply,it was of great help.
    cheers,
    Sajit
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!