File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

file downloading concept

 
Gabriel Arun Rayappan
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi frds,
I am a beginner in java. i need all your support to go with java developing..See friends, I am going to include downloading concept in my web application. In my home(jsp) page,i will have 3 categories. they will be themes, games, wallpapers. for category there will be 5 images will be placed. When the user wants to download particular thing, user has to click that image and it will be downloaded.. I need your step by step guidance.....
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there and welcome to Javaranch!

Hint 1: Search this forum for some potential answers, this question has been covered before....
Hint 2: Have you taken a look at the various Javaranch FAQ sections? There's one there on file downloads...

Hope that helps!
 
Gabriel Arun Rayappan
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi i tried the following code in servlet...while run this project, file download dialog box is opening... but the image is written for 100 bytes only.....i dont know why it is constantly written 100bytes...it is downloaded....but it is not opening in print and fax viewer.....

jsp page



servlet :


 
Ankit Garg
Sheriff
Posts: 9497
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well I'm not sure but this statement might be causing problems

int size=fin.available();

I read the documentation of the available method which is not very clear for me but this might be it

Returns an estimate of the number of remaining bytes that can be read (or skipped over) from this input stream without blocking by the next invocation of a method for this input stream. The next invocation might be the same thread or another thread. A single read or skip of this many bytes will not block, but may read or skip fewer bytes.

In some cases, a non-blocking read (or skip) may appear to be blocked when it is merely slow, for example when reading large files over slow networks.


I don't know what exactly this means but there might be a case that because of this you are getting only the first 100 bytes...
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Besides that, your code is also quite inefficient and buggy. What would happen if JVM has 128MB of heap space available and you allocate a byte[] based on the file length which more than 128MB? Or when 10 users simultaneously download files which are together more than 128MB in size? Yes, your application will crash with OutOfMemoryError.

Buffer the streams. The file size is irrelevant as far. 10KB is a decent buffer size.
You may get ideas out of this: http://balusc.blogspot.com/2007/07/fileservlet.html
 
Gabriel Arun Rayappan
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi friend, still i couldnt able to do that.please give step by step guidance.....please someone help me...
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Start here: AvailableDoesntDoWhatYouThinkItDoes
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic