import java.io.*;
class BufferedWriterCopyTest02
{
public static void main(String[] args)
{
BufferedWriter bw = null;
BufferedReader br = null;
try
{
br = new BufferedReader(new FileReader("bw.txt"));
bw = new BufferedWriter(new FileWriter("copy_bw.txt"));
String lion = null;
while((lion=br.readLine())!=null)
{
bw.write(lion);
bw.newLine();
bw.flush();
}
}
catch (IOException e)
{
/*
疑问,当不注释掉throw时,在编译时会出现错误,非法字符,这是为什么
*/
throw new RuntimeException("复制失败");//出现错误的位置
}
finally
{
try
{
if(bw!=null)
bw.close();
}
catch (IOException e)
{
throw new RuntimeException("写出流关闭失败");//出现错误的位置
}
try
{
if(br!=null)
br.close();
}
catch (IOException e)
{
throw new RuntimeException("读入流关闭失败");//出现错误的位置
}
}
}
}
在编译时就出现了,但把出现3个错误的代码都注释掉后程序能正常运行且结果正确,请问为什么会出现这些错误?? |
|