追加字符串到文本文件末尾
测试可以运行
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
package com.sec.file; import java.io.FileOutputStream; import java.io.IOException; public class addLastTxt { public void fileOutputStream() throws IOException{ String temp="Hello world!\n"; FileOutputStream fos = new FileOutputStream("f:\\c.txt",true);//true表示在文件末尾追加 fos.write(temp.getBytes()); fos.close();//流要及时关闭 } public static void main(String[] args) throws IOException { new addLastTxt().fileOutputStream(); } } |
未经允许不得转载:Java学习 » java代码 追加字符串到文本文件末尾,txt追加(可运行)
不错,可以解决问题了
网站真不错 爱奇趣网http://www.iqiqu.net/?
很好的网站,赞一个,加油!
无意溜达到了这里,留下足迹