328.io流(字符串-练习-复制文本文件一)

public static void main(String[] args) {
// TODO Auto-generated method stub
FileReader fr = null;
FileWriter fw = null;
try {
fr = new FileReader("demo.txt");
fw = new FileWriter("cope.txt");
int ch = 0;

//每次只读一个字节

while ((ch = fr.read()) != -1) {
fw.write(ch);
}

} catch (Exception e) {
// TODO: handle exception
throw new RuntimeException("复制失败");
}finally {
if (fr != null) {
try {
fr.close();
} catch (Exception e2) {
// TODO: handle exception
}
}
if (fw != null) {
try {
fw.close();
} catch (Exception e2) {
// TODO: handle exception
}
}

}



}

posted @ 2018-08-04 10:15  仙人掌的成长  阅读(176)  评论(0编辑  收藏  举报