为什么我会收到以下异常?我正在做的是逐行将一个巨大的 ArrayList 写入磁盘上的文件。生成的文件大约 >700MB。逐行编写时似乎有一些问题。文件的大小可能是一个原因吗?为什么要关闭流?顺便说一句,我正在使用 Windows 操作系统。
FileWriter evaluated_result =
new FileWriter(path_output+this.algorithm+"/"+query_type+"/"+"queries.eval");
BufferedWriter out = new BufferedWriter(evaluated_result);
out.write(Myobject);
out.newLine();
evaluated_result.close();
out.close();
例外情况如下:
java.io.IOException: Stream closed
at sun.nio.cs.StreamEncoder.ensureOpen(StreamEncoder.java:45)
at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:118)
at java.io.OutputStreamWriter.write(OutputStreamWriter.java:207)
at java.io.BufferedWriter.flushBuffer(BufferedWriter.java:129)
at java.io.BufferedWriter.close(BufferedWriter.java:264)
at Assignment_1.Query_Evaluator.write100BestDocumentsEvalFormat(Query_Evaluator.java:85)
at Assignment_1.Experiment.ConductExperiment(Experiment.java:54)
at Assignment_1.Main.main(Main.java:78)