Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How to write newline in CSV file?

Tags:

java

android

csv

I am trying to organize my data in .CSV file.I want to put my data in a particular row so i tried putting "\n" but it is not working.Please help me in putting data to a particular row.Thank you in advance..

public void writeData(String data,String strFilePath)
        {

            PrintWriter csvWriter;
            try
            {

                File file = new File(strFilePath);
                if(!file.exists()){
                    file = new File(strFilePath);
                }
                csvWriter = new  PrintWriter(new FileWriter(file,true));


                csvWriter.print(data+","+"hello");
                csvWriter.append('\n');
                csvWriter.print("world");


                csvWriter.close();


            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
        }
like image 361
swetha kini Avatar asked Sep 03 '12 04:09

swetha kini


1 Answers

  1. try flush your stream before you close it csvWriter.flush()
  2. instead using print, try println
like image 60
user902383 Avatar answered Sep 21 '22 05:09

user902383