プログラミングの最終試験のために勉強しています。文字列fileNameに格納されているファイルを開き、ファイルでpersonNameという文字列を探すプログラムを作成する必要があります。これにより、personNameの後に最初の文字列が出力され、引数personNameがファイルにない場合は、「この名前は存在しません」と出力し、IOExceptionが発生した場合は、「IOエラーがあります」と出力し、プログラムはsystem.exit(0)を使用して終了する必要があります。
プログラムはファイルinfo.txtを使用する必要があり、各行には最初の文字列名と2番目の年齢の2つの文字列が含まれている必要があります。
すべてが1つの方法である必要があります
data.txtには
最大60.0
ジョー19.0
アリ20.0
これまでの私のコードは:
public class Files{
    public void InfoReader(String fileName, String personName)
    {
      try{
         try{
                   // Open the file that is the first 
                  // command line parameter
                  FileInputStream fstream = new FileInputStream("C://rest//data.txt");
                  // Get the object of DataInputStream
                  DataInputStream in = new DataInputStream(fstream);
                  BufferedReader br = new BufferedReader(new InputStreamReader(in));
                  //Read File Line By Line
                  while ((fileName = br.readLine()) != null) {
                      // Print the content on the console
                      (new Files()).infoReader("info.txt","Joe"); //this prints the age
                  }
                  //Close the input stream
                  in.close();
              }
              catch (IOException e)
              {//Catch exception if any
                    System.out.println(" there is an IO Error");
                    System.exit(0);
              }
     }
    catch (Exception e)
              {//Catch exception if any
                    System.out.println("that name doesn't exists");
              }
    }
}
infoReader(info.txt,Joe);印刷する必要があります19.0
が、私はjava.lang.StackOverflowError
どんな助けでも大歓迎です!!
前もって感謝します!