This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
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: 39576
    
  27
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 - updated with new look and Ping home screen widget
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: 39576
    
  27
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 !
 
Similar Threads
file download !
downloading text file in jsp
file download dialog box - help me out
File Download problem with word/excel ?? only
file download dialog box