import java.io.*;
public class TextFileReaderLine
{
String filename;
FileReader fw;
public TextFileReaderLine(String f)
{
filename = f;
try
{
fw = new FileReader(new File(f));
} catch (IOException e)
{
}
}
public void readLine()
{
char ch = '\u0000';
try
{
while (ch != -1)
{
ch = (char) fw.read();
System.out.print(ch);
}
} catch (IOException e)
{
System.out.print("Error!");
}
}
public static void main(String args[])
{
TextFileReaderLine frs = new TextFileReaderLine("text1.txt");
frs.readLine();
}
}
Exception in thread "main" java.lang.NullPointerException
at TextFileReaderLine.readLine(TextFileReaderLine.java:27)
at TextFileReaderLine.main(TextFileReaderLine.java:39)
就是Read()函数与ReadLine()函数的调用问题,其实质是未实例化的调用,但是怎么修改呢?还是因为其他的错误呢??O(∩_∩)O谢谢! |
|