Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi All,

I have a big problem when down load a file on device.
The my file was downloaded from my android device is empty(file size = 0) while I down load from my computer have data(file size > 0).(I am using Chrome browser, and code on java).

I don't know why the downloaded is empty file?

Help me resolve this

Thanks in advance


Java
public void download(HttpServletResponse response, InputStream attachObj){
   OutputStream os = response.getOutputStream();
   BufferedInputStream bis = null;
   try{
       response.setHeader("Pragma", "private");
       response.setHeader("Cache-Control", "private");
       response.setHeader("Expires", "-1");
       response.setContentType("application/octet-stream");
       response.setHeader("Content-Disposition", "attachment;" + "filename*=utf-8''" + filename);
       response.setHeader("Content-Length", filesize);
       bis = new BufferedInputStream(attachObj);
       int c;
       while ((c = bis.read()) != -1) {
           os.write(c);
       }
   }
   finally {
       os.flush();
       os.close();
       bis.close();
   }
}
Posted
Updated 18-Jan-16 0:33am
v2
Comments
Richard MacCutchan 28-Dec-15 7:54am    
Resolve what? We have no idea what is going on or where the file is coming from or going to. You need to use your debugger to find out where the failure occurs in your code.
ridoy 28-Dec-15 11:49am    
Your question is not clear enough to answer.
ngthtra 28-Dec-15 21:37pm    
my problem is why my download file is empty when down on android(chrome browser) but on PC is have data. I debugged on android device, the flow process are same between PC and android device and they were not happen any error.

when debugged on device:
- While command: run normal.
- os.write(c) is also run OK
But after os.flush() and os.close(). the data are not write to downloaded file.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900