이것은 내가 작성한 코드입니다. 하지만 때 키 및 값을 null 포인터를 가져 오는 값을 인쇄하려면 노력하고있어.컴퓨터에있는 속성 파일을로드 할 때 Null 포인터 예외가 발생합니다.
내 주요 관심사, 특성 파일에서 키와 값을로드하고 등록 정보 파일에 당신이 절대 경로를 가지고 있기 때문에지도
Map<String, String> prop1 = new HashMap<String, String>();
Map<String, String> prop2 = new HashMap<String, String>();
public static void main(String args[]) {
Sample sample = new Sample();
sample.getLocaleOne();
}
public void getLocaleOne() {
Properties prop = new Properties();
InputStream input = null;
try {
File file = new File("Labels.properties");
System.out.println("file.getAbsolutePath());
input = this.getClass().getClassLoader().getResourceAsStream("C:/workspaceNewI18NChnages/customer/Labels.properties");
prop.load(input);
Enumertion<?> e = prop.propertyNames();
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
String value = prop.getProperty(key);
System.out.println("Key : " + key + ", Value : " + value);
}
} catch (Exception e) {
e.printStackTrace();
}
}
에 위치하며 사진으로 코드를 절대 게시 할 수 없습니다. 항상 질문에 넣으십시오 – XtremeBaumer
사실, 이것은 실제로 루틴 널 포인터 문제가 아니며 잘못된 유형의 스트림을 사용하여 속성 파일을로드하고 있습니다. –
getResourceAsStream은 클래스 경로에서 사용 가능한 자원을로드하기위한 것이지만 절대 파일 경로를 제공합니다. http://www.javaworld.com/article/2077352/java-se/smartly-load-your-properties.html을보십시오 – haggisandchips