2 java resources bundle properties file
我想在我的java类中读取属性文件.
为此我写了:
try {
Properties property = new Properties();
property .load(new FileInputStream("abc.properties"));
String string = property.getProperty("userName");
} catch (Exception e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
我已将我的abc.properties文件放在我的java类所在的同一个包中.但我得到FileNotFound异常.
请让我知道如何提供属性文件的路径.
感谢致敬
FileInputStream将在程序的"工作目录"中查找该文件,而不是在与您的类相同的包中.
您需要使用getClass().getResourceAsStream("abc.properties")从同一个包中加载属性文件.