1

I am trying to write a 2D array into a CSV file using OpenCSV API. I have the following method:

    Path path = Paths.get("/Users/Home/");
    String[][] d = new String[10][10];
    CSVWriter writer =
            new CSVWriter(Files.newBufferedWriter(path.resolve("data.csv"),StandardOpenOption.CREATE_NEW));
    writer.writeNext(Arrays.asList(d));  // Does not work!
    writer.close();

In fact, writer.writeNext(Arrays.asList(d)) does not work and I am getting stuck in this. Any help is appreciated.

1 Answer 1

1

From the docs of CSVWriter writeNext expects a String array. You could iterate as follows

for (int i=0; i < d.length; i++) {
   writer.writeNext(d[i]);
}
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.