Java Formatter不允许新行字符? [英] Java Formatter not allowing new line character?

查看:166
本文介绍了Java Formatter不允许新行字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我有以下代码写入文件:

So, I've got the following code to write to a file:

Formatter output = ....... // Creating the formatter works, writes to appropriate file.

output.format("%d\n", records.length);
for(GradeRecord gR:records)
{
    output.format(gR.toString() + "\n");
}

唯一的问题是,输出没有换行符。

Only problem is, the output doesn't have newline characters.

如果我用\ n替换\ n,则不起作用。

Doesn't work if I replace "\n" with "\r", either.

..我不知道为什么这不起作用。输出已创建并正确写入。 (我看到创建的文件,所有内容都写在里面,换行符除外。)

...I don't know why this doesn't work. Output is created and writes correctly. (I see the file created and everything is written in it, except for newline characters.)

推荐答案

你可以使用格式 %n使用格式化程序输出特定于平台的换行符。

you can use the format "%n" to output the platform specific newline using a formatter.

这篇关于Java Formatter不允许新行字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆