解決できない問題があります。 プロパティファイルを読み込む必要がありますが、正しいパスを設定することはできません。 java.io.Fileのドキュメントは、私がsrc/...から設定しなければならないと言っています。 それはうまくいかない、私は現在のファイルからパスを行い、同じ問題があります。プロパティファイルの正しいパスを設定する方法は?
は例外です:にFileNotFound
PropertyReaderクラス:
public final class PropertyReader {
private Properties prop = new Properties();
private InputStream input = null;
public Properties getProperties(File file) {
try {
input = new FileInputStream(file);
// load a properties file
prop.load(input);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (null != input) {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return prop;
}
}
そしてApplicationController.class PropertyReaderを使用しています。
@RequestMapping(value = "/result", method = RequestMethod.GET)
public String resultPage(ModelMap model) {
//Getting property with key "path"
model.addAttribute("path", new PropertyReader().getProperties(file).getProperty("path"));
return "result";
私はCからのパスを設定していた場合: // ..うまく動作します。
ありがとうございましたし、良い一日を!
性質がどのようにあなたが 'あなたを作成したリソースフォルダ –
にファイルを入れてくださいファイル 'オブジェクト – Sanjeev
ファイルファイル=新しいファイル("ここでファイルへのパス "); –