This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach 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 Murach's Java Servlets and JSP this week in the Servlets 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: 41034
    
  43
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: 41034
    
  43
JSPs generally insert additional whitespace. The best way to avoid that is to use a servlet instead.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: file download !
 
Similar Threads
file download !
file download dialog box
File Download problem with word/excel ?? only
downloading text file in jsp
file download dialog box - help me out