Exception in thread "main" java.lang.NullPointerException
at java.io.Reader.<init>(Unknown Source)
at java.io.InputStreamReader.<init>(Unknown Source)
//at InputStreamReader inStream = new InputStreamReader(fis);
また、IOException、FileNotFoundExceptionをmainにスローするか、代わりにtry {}を使用する必要がありますか?スレッド "main"の例外java.lang.NullPointerException
System.out.print("Enter the filename: ");
Scanner stdin = new Scanner(System.in); //Keyboard input
String fileName=stdin.nextLine();
FileInputStream fis = null;
try {
fis = new FileInputStream(fileName);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
InputStreamReader inStream = new InputStreamReader(fis);
BufferedReader in = new BufferedReader(inStream);
あなたの質問は何が間違っていたか、そして/またはあなたはそれについて何をすべきですか? – nmagerko
私は両方の答えが役に立つと思います。 – user93200
ファイルの入力ストリームがnullのようです。コードの下の2行をtryブロックに移動する必要があります。一般的な習慣として、例外を飲み込むことは悪い考えです。 – Perception