已经在关闭资源的时候作出了空指针的判断,为何在读文件产生错误的时候
除了 File read error !还有 nullpointerException ?请帮忙看看,谢谢了啊
import java.io.*;
class FileReaderDemo2
{
public static void main(String[] args)
{
FileReader fr = null;
char buf[] = new char[1024];
int num = 0;
try
{
fr = new FileReader("love.txt");
while ((num = fr.read(buf))!= -1)
{
System.out.println(new String(buf,0,num));
}
}
catch (IOException e)
{
System.out.println("File read error !");
}
finally
{
try
{
if(fr!= null);
fr.close();
}
catch (IOException e)
{
System.out.println("File close error !");
}
}
}
}
|