"\ n"定界符问题 [英] "\n" delimiters issue

查看:55
本文介绍了"\ n"定界符问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个stringbuilder对象,其中添加了一行数据.

I have a stringbuilder object, that a line of data gets added to.

在添加每行之后,我在末尾添加"\ n"以表示新行.

after each line gets added, I append a "\n" on the end to indicate a new line.

最终确定的此stringbuilder对象将被写入平面文件.

this stringbuilder object, finalised, gets written to a flat file.

当我在记事本中打开平面文件时,每行之后都会出现一个小矩形,并且列格式被破坏了.

When I open the flat file in notepad I get a small rectangle after every line and the column formatting is ruined.

当我在写字板中打开平面文件时,会考虑换行,并且列格式是完美的.

When I open the flat file in wordpad, the new line is taken into consideration and the column formatting is perfect.

我已经尝试了所有知道的方法来删除新行,然后再写入新行,但这会在写入平面文件时删除格式.我需要使用新行来设置列的格式.

I have tried all ways I know of removing the new line entry before it gets written, but this removes the formatting when written to the flat file. I need the new line for the formatting of the columns.

如何在不使用\ n的情况下用换行符输出文件?

how can I output the file with new lines but without using \n?

推荐答案

Windows终止行的方法是使用"\ r \ n",而不仅仅是"\ n".

The Windows way of terminating a line is to use "\r\n", not just "\n".

您可以使用 line.separator 系统属性找到当前操作系统的行分隔符":

You can find the "line separator for the current operating system" using the line.separator system property:

String lineSeparator = System.getProperty("line.separator");
...
StringBuilder builder = new StringBuilder();
...
builder.append(lineSeparator);
...

这篇关于"\ n"定界符问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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