直接上代码了,IO学习(六)有详细内容,写多了其实发现字节流字符流的也都差不多,读取写入拷贝思路也一样,
第一次学IO也被各种类搞得头昏,这一次再学习就清晰很多了,关键还是多多联系总结,共勉
public class Demo05 {
public static void main(String[] args) {
/**
* 纯文本的拷贝
*/
File src=new File("F:/Picture/test/test.txt");
File dest=new File("F:/Picture/test/test3.txt");
Reader re=null;
Writer wr=null;
try {
re=new FileReader(src);
wr=new FileWriter(dest);
char[] buffer=new char[1024];
int len=0;
while(-1!=(len=re.read(buffer))){
wr.write(buffer);
wr.flush();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
if (wr != null) {
wr.close();
}
if (re != null) {
re.close();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}