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 Writing CSV file 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 "Writing CSV file" Watch "Writing CSV file" New topic
Author

Writing CSV file

Mike Jeya
Ranch Hand

Joined: Apr 15, 2004
Posts: 54
Hi,
we need to create the CSV file . problem is some column value have comma in it, because of which the file format is changed.
can you please let me know the procedure to take care of comma values too,


RandomAccessFile raf = new RandomAccessFile(file, "rw");
raf.seek(file.length());
raf.writeBytes(new StringBuffer(strUID+","
+strFirstName+","+strLastName+","+strMail+","+strTelephone+","+groupName+"\n").toString());
raf.close();

please advise me.....
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41052
    
  43
You need to enclose all cells contents by quotes, so that they look like this:

There are other characters that need to be treated especially (like doubles quotes and newlines), so you may be better off using one of the readily available CSV libraries. The http://faq.javaranch.com/java/AccessingFileFormats lists several.


Ping & DNS - my free Android networking tools app
Rajasekhar Pentakota
Ranch Hand

Joined: Aug 28, 2007
Posts: 38



Thanks
Raja
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Writing CSV file
 
Similar Threads
Need your's Help
CSV to XML coding in Java
Creating XML -- Need help
Problem in csv file upload
ignoring comma in CSVWriter