预备知识:
1. 继承关系:
└───Writer
├───BufferedWriter
└───OutputStreamWriter
└───FileWriter
└───Reader
├───BufferedReader
└───InputStreamReader
└───FileReader
private static void myfunc3() throws IOException
{
//1 write
BufferedWriter bufw = new BufferedWriter(new FileWriter("buf.txt"));
bufw.write("abcde");
bufw.newLine();
bufw.write("fg");
bufw.flush();
bufw.close();
//2 read
BufferedReader bufr = new BufferedReader(new FileReader("buf.txt"));
String line = null;
while( null != ( line = bufr.readLine()) )
{
System.out.println("read line:" + line);
}
bufr.close();
}
运行结果:
read line:abcde
read line:fg
1. 继承关系:
└───Writer
├───BufferedWriter
└───OutputStreamWriter
└───FileWriter
└───Reader
├───BufferedReader
└───InputStreamReader
└───FileReader
{
//1 write
BufferedWriter bufw = new BufferedWriter(new FileWriter("buf.txt"));
bufw.write("abcde");
bufw.newLine();
bufw.write("fg");
bufw.flush();
bufw.close();
//2 read
BufferedReader bufr = new BufferedReader(new FileReader("buf.txt"));
String line = null;
while( null != ( line = bufr.readLine()) )
{
System.out.println("read line:" + line);
}
bufr.close();
}
运行结果:
read line:abcde
read line:fg