package cn.itcast_02;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
//字符流写该字符串数组到文件中
/*
* 1.创建字符串数组,封装文本文件
* 2.遍历
* 3.写字符串
* 4.释放资源
*/
public class IODemo {
public static void main(String[] args)throws IOException {
String[]strs={"hello","world","java"};
BufferedWriter bw=new BufferedWriter(new FileWriter("aaa.txt"));
for(String str:strs){
bw.write(str);
bw.newLine();
bw.flush();
}
bw.close();
}
}
|