在java中编写文本文件 [英] write text file in java

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

问题描述

如何将字符串写入文件,通过我的程序更新文件?

(我想在每次文本文件末尾写入)

how can i write string to a file , an update the file through my program?
(I want to write at the end of the text file each time)

推荐答案

这些应该让你入门,



http://www.javapractices.com/topic/TopicAction.do?Id=42 [ ^ ]



http://www.abbeyworkshop.com/howto/java/writeText/ [ ^ ]
These should get you started,

http://www.javapractices.com/topic/TopicAction.do?Id=42[^]

http://www.abbeyworkshop.com/howto/java/writeText/[^]






试试这个:

Hi,

Try this:
FileWriter writer = new FileWriter("file.txt");
writer.write("Some text to append...");
writer.close();



如果文件包含This is text。,并且如果执行此代码,那么您的文本文件将包含此内容:


If a file contains "This is text.", and if you execute this code, then your text file will contain this:

This is text.Some text to append...



如果你想要一个新的一行这是文本,然后使用转义序列换行:


If you want a new line after "This is text", then use the escape sequence for a new line:

FileWriter writer = new FileWriter("file.txt");
writer.write("\nSome text to append...");
writer.close();



在这种情况下,你的文本文件将包含:


In that case, your text file will contain this:

This is text.
Some text to append...



希望这会有所帮助。


Hope this helps.


这篇关于在java中编写文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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