어딘가에 텍스트 파일을 만드는 간단한 자바 프로그램을 만들고 싶습니다. 사용자가 폴더를 선택할 수있게하고 싶습니다. 하지만 jar 파일로 포장하고 다른 사람들에게 보냅니다. 내 친구가 그것을 실행할 때마다 폴더를 묻습니다. 항아리 파일에 한 번만 묻고 마지막으로 설정하도록 할 수있는 방법이 궁금합니다. 내 된 .java 파일 내부 , 나는 당신이 어딘가에 사용자 설정을 저장해야사용자 기본 설정
public void setDefaultFolder() {
//initially path is empty string
if(fc.getPath().equals("")){
String a = JOptionPane.showInputDialog("Please select a default folder." +
" Make sure it exists and it's not changeable once set");
if(a != null) {
String b = a.replace("\\","\\\\");
// set String path = something users enter
// fc is a helper object. I have all the read/write file or other methods
// there. I want to let the jar file read the path only for the first time
// and set the path final, later on, when it detects path is not empty
// string, it stops asking users to type in path.
fc.setPath(b);
}
else {
JOptionPane.showMessageDialog(null, "Folder not set");
}
}
}
구성 파일에 저장하십시오. 구성 파일이 있으면 경로를 읽으십시오. 그렇지 않다면 요청하여 저장하십시오. – m0skit0
if 문을 비우는 방법을 추가하는 방법, JOpitionPane.showInputDialog를 실행하도록하고 싶습니다. 비어 있지 않으면 입력 대화 상자를 실행하지 않습니다. –