FileWriter中的换行符 [英] Newline in FileWriter

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

问题描述

如何在FileWriter中生成新行?似乎\ n不起作用。

How do you produce a new line in FileWriter? It seems that "\n" does not work.

log = new FileWriter("c:\\" + s.getInetAddress().getHostAddress() + ".txt", true);    
log.append("\n" + Long.toString(fileTransferTime));
log.close();

上面代码的文件输出只是一串没有新行的数字。

The file output of the code above is just a long string of numbers without the new line.

推荐答案

我会猜测你是在打开 .txt 文件,只显示 \ n 的换行符。

I'll take a wild guess that you're opening the .txt file in Notepad, which won't show newlines with just \n.

你试过吗?使用系统特定的换行符组合?

Have you tried using your system-specific newline character combination?

log.append(System.getProperty("line.separator") + Long.toString(fileTransferTime));

这篇关于FileWriter中的换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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