@Test
public void testWrite() throws IOException {
FileWriter fWriter = new FileWriter("E:/test/filewrite.txt");
fWriter.write("Hello Subeyz!\r\n");
fWriter.write("How Are You!\r\n");
fWriter.write("I miss you xb!");
// 字符流必须刷新缓存--flush()
// 但是关闭方法最终也会自动刷一次--close()
fWriter.flush();
fWriter.close();
}
@Test
public void testRead() throws IOException{
FileReader fReader = new FileReader("E:/test/filewrite.txt");
char cbuf[] = new char[16];
int len = 0;
while((len = fReader.read(cbuf))>0){
String string = new String(cbuf, 0, len);
System.out.print(string);
}
fReader.close();
}
这里只做简单演示,没有使用标准的异常处理方式,应该抓一下异常!