30

私のプロジェクトのディレクトリ構造(Eclipse):

MyProject/
    src/        --> "source directory" on Eclipse's classpath/buildpath
        com.me.myapp
            Driver
            myconfig.txt

にはDriver、次のコードがあります。

public class Driver {
    public static void main(String[] args) {
        InputStream is = ClassLoader.getSystemClassLoader.getResourceAsStream("myconfig.txt");
        if(is == null)
            System.out.println("input stream is null");
        else
            System.out.println("input stream is NOT null :-)");
    }
}

これを実行すると、次のコンソール出力が得られます。

input stream is null

なんで?myconfig.txt間違った場所に配置しましたか? ClassLoader API を間違って使用していますか? 他の何か?前もって感謝します!

4

3 に答える 3