Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Writing CSV file

 
Mike Jeya
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rajasekhar Pentakota
Ranch Hand
Posts: 38
Java MyEclipse IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic