Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Issue with CSV file generated using Java  RSS feed

 
Dilip kumar
Ranch Hand
Posts: 360
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All -

Our java application (servlets) has the option of generating a CSV file. We are adding LineFeed "\n" after each record we read from the database. But when we save the file we are seeing an "extra" Line Feed (0A) at the end of the file. Is there anyway we can eliminate this extra Line Feed programatically ?

Really appreciate any suggestions.

Thanks much.

[ January 20, 2007: Message edited by: Dilip kumar ]
[ January 20, 2007: Message edited by: Dilip kumar ]
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you writing the data? Are you using println or similar? are you outputting from a JSP? both could result in additional line feeds
 
Dilip kumar
Ranch Hand
Posts: 360
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the response.

StringBuffer sb = new StringBuffer();
String str = "";
:
:
while (rs.next()) {
sb.append(rs.getString(1));
sb.append("\n");
}
str = sb.toString();
outString = str;


Users will get the "File Download" window to save the file onto their PC. We are using
response.setHeader("Content-Disposition","attachment; filename=reportdata.csv") for this.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep, but what do you do with the 'outString'?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, do you check that the value retrieved from the DB doesn't already have the '\n'?
 
Dilip kumar
Ranch Hand
Posts: 360
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
WebPage wp = new WebPage();
wp.contents (outString);
wp.output(response.getOutputStream());


Right now I don't have code for WebPage.class with me but I think it is from WebLogic
http://www.beasys.co.jp/e-docs/wls61/javadocs/weblogic/html/WebPage.html

No. We are not getting LineFeed from DB records.


Thanks much.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!