Java 프로그램에 여러 값을 저장하는 등록 정보 파일이 있습니다. 설정 창에서 사용자는 다음 번에 프로그램을 실행할 때이 값을 편집하고 수정 사항을 저장할 수 있습니다. 여기등록 정보 파일의 변경 사항이 JAR 파일 내에 저장되지 않습니다.
public class AppProperties {
private final static AppProperties appProperties = new AppProperties();
private static Properties properties;
private final static String preferencesSourcePath = "/res/pref/Properties.properties";
private AppProperties() {
properties = new Properties();
try {
properties.load(getClass().getResourceAsStream(preferencesSourcePath));
} catch (IOException e) {
e.printStackTrace();
}
}
그리고, (같은 클래스) 속성의 파일 속성을 저장하는 방법 :
public static void saveAppPropertiesFile() {
try {
OutputStream outputStream = new FileOutputStream(new File(AppProperties.class.getResource(preferencesSourcePath).getPath()));
properties.store(outputStream, null);
} catch (IOException e) {
e.printStackTrace();
}
}
}
내가 여기
속성은 등록 정보 파일을 형성로드 코드입니다 이 기능을 시도해 보았습니다. IDE에있을 때 작업을 훌륭하게 수행했지만 JAR 파일을 실행할 때 작동하지 않습니다. 사실 현재 세션에서 작동하지만 JAR 파일에는 저장되지 않습니다. 나는이 수행하려고 할 경우java.io.FileNotFoundException: file:\C:\Users\HP\HEIG\EcoSimSOO\out\artifacts\EcoSimSOO_jar\EcoSimSOO.jar!\res\pref\Properties.properties (La syntaxe du nom de fichier, de répertoire ou de volume est incorrecte)
at ...
at res.pref.AppProperties.saveAppPropertiesFile(AppProperties.java:31)
은 다음과 같습니다 : 콘솔에서
, 그것은 말을 내가 this post을 읽고AppProperties.class.getResource(preferencesSourcePath)
을하지만 난 문제와 내가 무엇을해야 이해가 안 돼요 이 문제를 해결하려면 ...
감사합니다.
jar IDE에서 절대 경로를 사용하는 동안 경로를 찾을 수없는 이유는 무엇입니까 – SarthAk
새로운 파일 (AppProperties.class.getResource (preferencesSourcePath) .getPath()) – SarthAk
경로를 인쇄하려고합니다. jar를 실행 중입니다. – SarthAk