好的,我在写入文本文件时遇到了一些麻烦。
程序可以运行,但每次都不会换行。
当我想要运行4次时,文本文件应该如下所示:
a
b
c
d
相反,它看起来像:
d
谁知道如何解决这个问题?所有导入都已经正确地导入了。
源代码(已稍作编辑,假设所有定义都是正确的):
import java.io.*;
public class Compiler {
public static void main (String args[]) throws IOException
{
//there's lots of code here
BufferedWriter outStream= new BufferedWriter(new FileWriter("output.txt"));
outStream.newLine();
outStream.write(output);
outStream.close();
}
}
output
未定义,所以显然无法编译。我假设它会运行4次,每次用字母表中后续的字母设置output
。如果output
的值是"a\nb\n\c\nd\n"
, 那么显然解决方案将大不相同。 - Collin Bell