This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan 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 Android Security Essentials Live Lessons this week in the Android 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: 41180
    
  45
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Writing CSV file
 
Similar Threads
Need your's Help
ignoring comma in CSVWriter
CSV to XML coding in Java
Creating XML -- Need help
Problem in csv file upload