本帖最后由 白磊 于 2013-5-13 12:35 编辑
import java.io.*;
public class A {
public static void main(String[] args) {
BufferedReader bufr = null;
BufferedWriter bufw = null;
try {
bufr = new BufferedReader(new FileReader("D:/workspace/a.txt"));
bufw = new BufferedWriter(new FileWriter("D:/workspace/b.txt"));
String line = null;
while ((line = bufr.readLine()) != null) {
bufw.write(line);
bufw.newLine();// 换行
bufw.flush();// 刷新缓冲区。
}
} catch (IOException e) {
throw new RuntimeException("读写失败");
} finally {
try {
if (bufr != null)
bufr.close();// 指向不为空,就关闭流对象。
} catch (IOException e) {
throw new RuntimeException("读取流关闭失败");
}
try {
if (bufw != null)
bufw.close();
} catch (IOException e) {
throw new RuntimeException("写入流关闭失败");
}
}
}
}
Exception in thread "main" java.lang.RuntimeException: 读写失败
at A.main(A.java:21)
就是这一句:
catch (IOException e) {
throw new RuntimeException("读写失败");
|