aspose file tools*
The moose likes I/O and Streams and the fly likes file download ! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "file download !" Watch "file download !" New topic
Author

file download !

subodh varshney
Greenhorn

Joined: Aug 01, 2005
Posts: 11
PrintWriter out1 = response.getWriter();
response.setContentType("application/octet-stream");
response.addDateHeader("Expires", 1);
response.setHeader("Content-Disposition","attachment;filename="+pagename);
out1.write(contents.substring(0,contents.length()).trim());


I m using above code it is working, but when i download file it includes some extra lines(whitespaces) in the haeder of the file
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41906
    
  63
You're not doing this in a JSP, are you? Because that wouldn't work.

Also, can you guarantee that the contents will always be text, never binary? "application/octet-stream" is generally used for binary content.


Ping & DNS - my free Android networking tools app
subodh varshney
Greenhorn

Joined: Aug 01, 2005
Posts: 11
yes, I m using JSP file.
content will always be text.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41906
    
  63
JSPs generally insert additional whitespace. The best way to avoid that is to use a servlet instead.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: file download !