java-文件处理

 1 import java.io.*;
 2 
 3 /**
 4  * @Author: Lambert
 5  * @Date: 2018-12-31 22:45
 6  * @Description:
 7  * java 写入文件
 8  */
 9 public class fileStreamTest2 {
10     public static void main(String[] args) throws IOException {
11         File file =new File("a.txt");
12         /**
13          * 构建FileOutputStream对象,文件不存在会自动新建
14          */
15         FileOutputStream fop=new FileOutputStream(file);
16         /**
17          * 构建OutputStreamWriter对象,参数可以指定编码,默认为操作系统默认编码,windows上是gbk
18          */
19         OutputStreamWriter writer =new OutputStreamWriter(fop);
20         /**
21          * 写入文件
22          */
23         writer.append("abc");
24         /**
25          * 关关闭写入流,同时会把缓冲区内容写入文件
26          */
27         writer.close();
28         /**
29          * 关闭输出流,释放系统资源
30          */
31         fop.close();
32 
33 
34     }
35 }
java将文本写入文件

猜你喜欢

转载自www.cnblogs.com/lizhen1412/p/10203572.html