2016-08-03 15 views
1

maven Webアプリケーションを使用しています。 プロパティファイルを配置したプロジェクトの構造は次のとおりです。

enter image description hereMavenプロパティファイルが見つかりません

次は、私がこのファイルを読むために使用しています私のコードです:

public static Properties loadProducerProperty() throws FileException { 
    Properties myProperties = new Properties(); 

    try { 
     String resourceName = "newproperties.properties"; // could also be a constant 
     ClassLoader loader = Thread.currentThread().getContextClassLoader(); 
     try (InputStream resourceStream = loader.getResourceAsStream(resourceName)) { 
      myProperties.load(resourceStream); 
     } 


    } catch (FileNotFoundException e) { 
     throw new FileException(); 
    } catch (IOException e) { 
     throw new FileException(); 
    } 

    return myProperties; 
} 

しかし、私は次のリンクを経て他のものを試してみましたFileNotFound例外

を取得しています同じエラーが発生しています:

Cannot load properties file from resources directory

私はここで間違っています。

答えて

2

は、ファイル名の前にスラッシュを追加ありがとう:

String resourceName = "/newproperties.properties"; // could also be a constant 
関連する問題