質問

いファイルを読み込むには、エラーを取得します

java.io.FileNotFoundException: /homes/at1106/fourthYearComputing/Individual-Project/svn-workspace/trunk/Individual_Project/src/game/player/gametheoryagent/configurations/gameTheoryAgentConfiguration.properties  (No such file or directory)
        at java.io.FileInputStream.open(Native Method)
        at java.io.FileInputStream.<init>(FileInputStream.java:106)
        at game.player.gametheoryagent.GameTheoryAgent.<init>(GameTheoryAgent.java:67)
        at simulation.Simulator.createPlayer(Simulator.java:141)
        at simulation.Simulator.main(Simulator.java:64)

しかし、ファイルに存在しているか確認しましたので777アクセス権を次のように記載してい

tui% cd /homes/at1106/fourthYearComputing/Individual-Project/svn-workspace/trunk/Individual_Project/src/game/player/gametheoryagent/configurations
tui% ls -al
total 4
drwxrwxrwx 3 at1106 cs4 1024 2010-02-22 17:45 .
drwxrwxrwx 4 at1106 cs4 1024 2010-02-22 17:27 ..
-rwxrwxrwx 1 at1106 cs4  260 2010-02-22 17:31 gameTheoryAgentConfiguration.properties
drwxrwxrwx 6 at1106 cs4 1024 2010-02-22 17:41 .svn

そのアイデアなどを理由になっていFNF例外?

感謝

javaコードの電話:

File file = new File(pathToConfiguration)
   Properties configuration = new Properties();
    try{
        configuration.load(new FileInputStream(file));
        int RAISE_RATIO = Integer.parseInt(configuration.getProperty("raise_ratio"));
    }
    catch(IOException event){
        System.err.println("Error in reading configuration file " + pathToConfiguration);
        event.printStackTrace();    
  }

のプロパティファイルを読み込み:

raise_ratio=4

この試験にはwindows(diff pathToConfiguration(コンストラクタに渡された)。

追加のチェックをCatchブロック

        if(file.exists()){
            System.out.println("file exists");
        }
        else{
            System.out.println("file doesn't exist");
        }

        System.out.println(file.getAbsolutePath());
        if(file.canRead()){
            System.out.println("can read");
        }
        if(file.canWrite()){
            System.out.println("can write");
        }

の出力は下記の様になります:

file doesn't exist
/homes/at1106/fourthYearComputing/Individual-Project/svn-workspace/trunk/Individual_Project/src/game/player/gametheoryagent/configurations/gameTheoryAgentConfiguration.properties
役に立ちましたか?

解決

初期スタックトレースによると、ファイル名と理由の間に2つのスペースがあるように見えます

FileNotFoundException: ...Configuration.properties  (No such file or directory)
--------------------------------------------------^^

このファイル名はおそらく末尾のスペースがあることを私に示しているでしょう。あなたは、二重で、あなたのpathToConfiguration変数を確認することができます:

System.out.println("[" + pathToConfiguration + "]");

ダブルチェックするためのパスは、あなたがそれは?

と思われるものであること

他のヒント

私と仮定しますが、二重回以上のパス名をチェックし、あなたがどこのコードが存在する同じマシン上でアプリケーションを実行していると言うようます。

それが唯一のログインシェルのためではなく、アプリケーションのために有効ないくつかのあいまいなNFS /ファイルサーバのマウント?

があるということだろう

あなたの$ HOMEにファイルをコピーしてみて、それが動作するかどうかを確認。

あなたがこれを書いた場合に出力する内容:

System.out.println(new File(".").getAbsolutePath());

現在のディレクトリは何ですか?

あなたのJavaプログラムを実行すると、あなたがコマンドラインのチェックを実行したときと同じ「ユーザー」として、それを実行している?

編集:あなたから、あなたのプログラムを実行したディレクトリにファイルをコピーしてみて、それを読み取ることができるかどうかを確認します。また、あなたの実行ディレクトリにファイルをコピーした後、次のことを試すことができます:

InputStream in = getClass().getResourceAsStream("/gameTheoryAgentConfiguration.properties");
configuration.load(in);

(あなたが持っていると仮定すると、 "" あなたのクラスパスに)

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top