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
}
}

}



}

每一步都是一个深刻的脚印
原文地址:https://www.cnblogs.com/chzlh/p/9417695.html