【发布时间】:2012-06-03 23:31:06
【问题描述】:
好的,我在将多行写入文本文件时遇到了一些问题。
程序运行,但不会每次都换行
当我希望它运行 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设置为字母表中的后续字母。显然,如果"a\nb\n\c\nd\n"是output的值,则解决方案将大不相同。
标签: java file filewriter