不做任何try,catch动作(仅在main(String args[])后添加throws IOException), 程序运行正常。try , catch 后编译通过,运行时报错:
Exception in thread "main" java.lang.NullPointerException
at L.main(L.java:16)
代码如下:
[code=java]import java.io.*;
class L
{
public static void main(String args[])
{
FileWriter fw=null;
FileReader fr=null;
try
{
new FileReader("L.java");
new FileWriter("mm.txt");
int len=0;
char[] buf=new char[1024];
while((len=fr.read(buf))!=-1)
{
fw.write(buf,0,len);
}
}
catch (IOException e)
{
throw new RuntimeException("error");
}
finally
{
if(fr!=null)
try
{
fr.close();
}
catch (IOException e)
{
}
if(fw!=null)
try
{
fw.close();
}
catch (IOException e)
{
}
}
}
}[/code] |