BufferedReader_WriterDemo

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;

public class BufferedReader_WriterDemo 
{
public static void main(String[] args) 
{
method();
}

private static void method()
{
File file = new File("d:\\a\\a.txt");//获取文件路径;
BufferedWriter bw = null;
BufferedReader br = null;
try 
{
bw = new BufferedWriter(new FileWriter(file));  
char[] c = {'a', 'b', 'c'};
bw.write(c);//将数组内容写入;
bw.newLine();//换行;
bw.write("aaaa");//继续写入内容;
bw.flush();//刷新;

br = new BufferedReader(new FileReader(file));
String line = null;
while((line = br.readLine()) != null)
{
System.out.println(line);//输出内容;
}
br.close();    //关闭流
bw.close();
} catch (Exception e) 
{
e.printStackTrace();
}
}
}

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/baidu_32731497/article/details/49962827
个人分类: Java
上一篇JAVA复制文件夹下所有内容
下一篇字节输入流缓冲区 BufferedInputStreamDemo
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭