public static void main(String[] args) throws IOException {
FileWriter fw = null;
try {
fw = new FileWriter("D:\\haha.txt");
fw.write("我爱java,我要学编程");
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fw != null) {
try {
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
FileReader fr = new FileReader("D:\\haha.txt");
FileWriter fw2 = new FileWriter("E:\\copy.txt");
int ch = 0;
while ((ch = fr.read()) != -1) {
fw2.write(ch);
}
fw2.close();
fr.close();
}
我想问一下,如果不写throws IOException,
FileReader fr = new FileReader("D:\\haha.txt");
FileWriter fw2 = new FileWriter("E:\\copy.txt");
这一部分是肯定会出错的
正常处理是丢包吗,老师讲的是推荐try/catch,但是我不会写下面这一部分,希望有人能写出来帮我看一下。 |
|