Win a copy of Classic Computer Science Problems in Swift this week in the iOS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

while opening csv file, dialog box opens twice  RSS feed

Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to open a csv file on the browser. I am facing the following problem :

WHen i click on the link that opens the csv file, it popups a window asking whether to OPEN /SAVE the file. If I click on OPEN, instead of opening the file, it again opens the same dialog box. On clicking the OPEN for the second time, it opens the file in excel.

I want the use to see the file only be clicking OPEN button for the first time.

The code snippet is as under:

File file = new File (fileName);
FileInputStreamfileStream = null;
// Open the file to download
fileStream = new FileInputStream (file);
// Read the contents of the disk file into an in memory byte array
intnumberOfBytes = fileStream.available ();
byte contents [] = new byte [numberOfBytes]; (contents);
ServletOutputStream out = res.getOutputStream();

res.setHeader("Content-Disposition","attachment;filename=\"" + downloadFileName + "\";");

out.write (contents);
out.flush ();

Thanks in advance,
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!