Jtextfield의 입력을 테스트 속성 설정 파일에 추가하려고합니다. 그러나 텍스트를 추가하려고 할 때마다 NullPointerException이 발생합니다. Properties API가 추가/제거/편집을 허용하지 않기 때문에 BufferedWriter도 시도했지만 작동하지 않는다는 것을 읽었습니다. 누구든지이 일을 할 수있는 방법을 알고 있다면 나는 매우 감사 할 것입니다. JButton를 통해JTextField to Properties 파일
덧붙이 텍스트 :
if (userField.getText().toString().equals("")) {
lblNullUser.setVisible(true);
} else {
lblNullUser.setVisible(false);
}
if(!chckbxRememberUser.isSelected()) {
//To do: go to Lynx
} else {
String user = userField.getText();
c.prop.setProperty("user", user); //null on this line; problem might be the key but not sure how to fix
try {
c.prop.store(c.outputSteam, null);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
구성 클래스 : 키 또는 값이 null의 경우
public String Config() throws IOException{
String result = "";
prop = new Properties();
propFileName = "config.properties";
inputStream = getClass().getClassLoader().getResourceAsStream(propFileName);
outputSteam = new FileOutputStream("config.properties");
prop.load(inputStream);
if (inputStream == null) {
throw new FileNotFoundException("Config file '" + propFileName + "' not found.");
}
//Date time = new Date(System.currentTimeMillis());
return result;
}
'c.prop '이 나오는 코드를 표시하십시오. –