jar 파일 내에서 속성 파일을로드하려고하는데 그렇게 할 수 없습니다. 다음은 파일을로드하는 클래스 코드입니다.
public class PropertyClass {
private static Properties properties;
public String getProperty(String propertyName) {
try {
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("resources/test.properties");
System.out.println("Input Stream " + inputStream);
properties.load(inputStream);
inputStream.close();
if (properties == null) {
System.out.println("Properties null");
}
} catch (IOException e){
e.printStackTrace();
}
return properties.getProperty(propertyName);
}
}
클래스 파일과 속성 파일은 모두 jar 안에 압축되어 있습니다. 하지만 다른 방법에서 파일을로드하려고 할 때 다음과 같은 오류가 발생합니다.
Input Stream - sun.net.www.protocol.jar.JarURLConnection$JarURLInputStream@9304b1
Exception in thread "main" java.lang.NullPointerException
at PropertyClass.getProperty(PropertyClass.java:16)
입력 스트림이 null로 표시되지 않습니다. 다음 비트는 내 코드의 16 행입니다. properties.load (inputStream);
이것에 대한 도움
Properties
다음을 호출하기 전에 개체 를 초기화해야 합니다 properties.load()
.
private static Properties properties = new Properties();
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다