您的位置:首页 > 其它

缓冲区字符流,写入内容到根目录下的hello.txt文件

2018-03-10 09:34 411 查看
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

/**
缓冲区字符流,写入内容到根目录下的hello.txt文件
*/
public class BufferWriterDemo {
public static void main(String[] args) {

try {
BufferedWriter bw=new BufferedWriter(new FileWriter("hello.txt"));
//String str="你好\r\n你好!";
String str="abcde";
for(int i=1;i<=20;i++) {

bw.write(str+"\t");

if(i%5==0) {
//换行.....
bw.newLine();
}
}
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
/*
运行的在hello.txt中得:

abcde	abcde	abcde	abcde	abcde
abcde	abcde	abcde	abcde	abcde
abcde	abcde	abcde	abcde	abcde
abcde	abcde	abcde	abcde	abcde

*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐