Bufferedwriter works, but file empty?

前端 未结 4 700
忘掉有多难
忘掉有多难 2020-12-11 08:58

I have the following code:

CSVmaker(LinkedList data) {
    String [] myLines = makeStrings(data);
  //  for (int k = 0; k

        
4条回答
  •  自闭症患者
    2020-12-11 09:47

    Starting with Java 8, one would simply do it with a try with resources, which automatically closes the BufferedWriter. Also see the usage of the new class Files

    try (BufferedWriter writer = Files.newBufferedWriter(somePath, yourCharset)){
        writer.write(output);
    }
    

提交回复
热议问题