使用用内存流读写文件的代码
我找了很久,想找到用内存流读写文件的代码。来分享一下吧:
导入Java . io . *;
公共类文本{
/* *
* @ param args
*/
public static void main(String[]args){
//TODO自动生成的方法存根
try {
File read = new File(" e:\ \ 1 . txt ");
File write = new File(" e:\ \ 2 . txt ");
buffered reader br = new buffered reader(
new file reader(read));
buffered writer bw = new buffered writer(
new file writer(write));
String temp = null;
temp = br . readline();
while(temp!= null){
//写入文件
bw . write(temp+" \ r \ n ");//只适用于Windows系统
//继续读取文件
temp = br . readline();
}
bw . close();
br . close();
} catch(找不到文件异常e){//找不到文件
system . out . println(e);
} catch(io exception e){
system . out . println(e);
}
}
位律师回复
0条评论