0

How can I go to new line in created .csv file. I can only go to next cell using ";"

File temp = new File("results11234.csv");
    FileWriter writer = new FileWriter(temp);

    for (int i = 0; i < dirs2.size(); i++) {
    try {
        writer.append(dirs.get(i)+ ';');

        writer.append((Integer.toString(dirs2.get(i)) + ';')); 

    } catch (Exception e) {
        e.printStackTrace();
    } finally {

    }
    }
     writer.flush();
     writer.close();
2
  • I can't understand. post your current output, and desired output Commented Sep 24, 2014 at 6:46
  • Make use of a didicated library like opencsv Commented Sep 24, 2014 at 6:55

1 Answer 1

1

You can add a line break:

writer.append("\n");   // for unix
writer.append("\r\n"); // for windows

If you want to be platform independent, you can do:

String lineSep = System.getProperty("line.separator");
...
writer.append(lineSep);

Or you use the BufferedWriter (the best way i think):

BufferedWriter writer = new BufferedWriter(new FileWriter(temp));
...
writer.newLine();

I hope, it helps

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.