package JAVA;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 JAVA.TextFileReaderLine.readLine(TextFileReaderLine.java:25) at JAVA.TextFileReaderLine.main(TextFileReaderLine.java:37)就是Read()函數與ReadLine()函數的調用問題,其實質是未實例化的調用,但是怎么修改呢?還是因為其他的錯誤呢??O(∩_∩)O謝謝!
有無大佬指點!關于JAVA文件流中Read()函數的問題
DIEA
2021-10-21 21:15:10