По какой-то причине я должен разместить свои *.properties
файлы за пределами Java-приложения. Когда файл km.properties
находится в java/src/resources/km.properties
, код читает файл, но когда я помещаю тот же файл в C:\Users\abc\Desktop\km.properties
это бросает
Exception: java.io.FileNotFoundException: property file 'C:\Users\abc\Desktop\km.properties' not found in the classpath
Exception in thread "main" java.lang.NullPointerException
at com.ir.Constants.<init>(Constants.java:44)
at com.Constants.main(Constants.java:64)
вот мой код
public class Constants {
public Constants(){
System.out.println(System.getenv("km_config"));
try {
Properties prop = new Properties();
String propFileName = System.getenv("km_config");
inputStream = getClass().getClassLoader().getResourceAsStream(propFileName);
if (inputStream != null) {
prop.load(inputStream);
} else {
throw new FileNotFoundException("property file '" + propFileName + "' not found in the classpath");
}
}
catch (IOException e) {
System.out.println("Exception: " + e);
}
catch (Exception e) {
System.out.println("Exception: " + e);
} finally {
try {
inputStream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public static void main(String[] args) throws Exception {
Constants c = new Constants();
System.out.println(Constants.DB_PATH1);
System.out.println(Constants.GIT_REPO_PATH);
System.out.println(Constants.GIT_MAIN_BRANCH_NAME);
System.out.println(Constants.TAGGER_PATH);
}
Constants.java:44
inputStream.close ();
Constants.java:64
является
Константы с = новые константы ();
, пожалуйста, помогите мне, мне нужно разместить km.properies
файл в любом месте за пределами Java-приложения
команда приводит к
echo %km_config%
C:\Users\abc\Desktop\km.properties