Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Issue with CSV file generated by servlet

Status
Not open for further replies.

DKL01

Programmer
Sep 14, 2000
233
US
Hi 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 ?

response.setHeader("Content-Disposition","attachment; filename=reportdata.csv");
:


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

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

Thanks much.
 
str = sb.toString();
outString = str.substring(0, str.length() -1);

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
I don't think the string has the "extra" Line Feed. With your suggestion it will trim the Line Feed coming from the code.

Bascially when I open the CSV file generated by application in Notepad I seeing
col1,col2,col3LF
col1,col2,col3LF
col1,col2,col3LFLF

But it should be
col1,col2,col3LF
col1,col2,col3LF
col1,col2,col3LF
 
Somewhere in your code, there is one extra character being added to your output.
My code alteration will remove one character from your data - so whatever is adding that other extra character should be now cancelled out by the modification.

Have you even tried the code ?

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top