0

When writing a column name into a CSV file through java the space between two words in a column comes up as double quotation marks...

eg. test_data[0][36] = "True Accept"; displays as True" Accept in the csv file..

Any ideas how this can be fixed?

Here is the code:

private void writeToCSV() throws IOException {
   CSVWriter writer = new CSVWriter(new FileWriter("list_of_churners.csv"),',',' '); 
   String [] data = new String[40]; 
   for(int i=0;i<341;i++)
   { 
      for(int k=0;k<40;k++)
      {      
         data[k] = test_data[i][k]; 
      }
      writer.writeNext(data); 
   }
   writer.close()
}

EDIT: Here is the solution:

CSVWriter writer = new CSVWriter(new FileWriter("list_of_churners.csv"),',','\t ');

Changing space ' ' to '\t' fixes the problem.

4
  • post your code that does the file writing. Commented Apr 24, 2012 at 12:53
  • 1
    What library are you using to write the CSV file? Also, post your code please. Commented Apr 24, 2012 at 12:53
  • private void writeToCSV() throws IOException{ CSVWriter writer = new CSVWriter(new FileWriter("list_of_churners.csv"),',',' '); String [] data = new String[40]; for(int i=0;i<341;i++){ for(int k=0;k<40;k++){ data[k]=test_data[i][k]; } writer.writeNext(data); } writer.close(); } Commented Apr 24, 2012 at 13:20
  • 1
    You can (and should) edit you original question instead of posting the code in a comment. I did that for you. For future reference, check out the formatting FAQs stackoverflow.com/editing-help and the general FAQs at stackoverflow.com/faq Commented Apr 24, 2012 at 13:55

1 Answer 1

1

Use a framework for writing and reading CSV files. I recommend OpenCSV.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.