File file = new File (directory + "Test.txt");
try {
BufferedWriter out = new BufferedWriter(new FileWriter(file, true));
out.write(in.read() + "This is a line of text.");
out.newLine();
out.close();
} catch (IOException e) {
}
我正在尝试将以下内容输出到文本文件中。设x表示BufferedWriter写入的行号:
“x。这是一行文字。”
但是我不知道如何这样做并且搜索了很长一段时间。有任何想法吗?谢谢!
答案 0 :(得分:0)
您可以使用in.readLine()方法而不是in.read()。
int linesCount = 0;
String currentLine = "";
while ((currentLine = in.readLine()) != null) {
linesCount++;
out.write(currentLine + "\n");
}