エラー:スレッド 'main'の例外java.io.FileNotFoundException:D: a.txt(システムは指定されたパスを見つけることができません。)



Error Exception Threadmainjava



IOストリームの学習で、hard disk.txtファイルからコンテンツを読み取るときに、実行エラーの問題が発生しました。

コードは次のように表示されます。



package cn.tedu.text import java.io.FileNotFoundException import java.io.FileReader import java.io.IOException public class FileReaderDemo { public static void main(String[] args) throws IOException { //Create file character input stream object //The bottom layer does not have its own buffer FileReader reader=new FileReader('F:\a.txt') //Return the encoding value of a single character /*System.out.println(reader.read()) System.out.println(reader.read()) System.out.println(reader.read()) //Flag of reading completed---return -1 System.out.println(reader.read())*/ //Achieved by loop int i=-1 //Assign the method return value (the character code value read) to the new variable, and then compare the new variable with -1 while ((i=reader.read())!=-1){ //Output the value of the new variable (the character code value read by the method) System.out.println(i) } } }

実行後、次の2つのエラーが報告されます。
画像
報告されたアクセス拒否エラー解決策:ドライブ文字を変更するだけです!
画像2番目のエラー:システムは指定されたパスを見つけることができません
見つかった問題:
ここで作成したのはフォルダです。
画像
解決:
テキストファイルを読むには、ファイルを作成する必要があります
画像
入力ファイルの内容:
画像
コード実行結果:(ここで、48は数値0の文字コード値です)
画像
OK!問題が解決しました!