我想制作一个简单的 java 程序,在某处创建一个文本文件。我想让用户选择文件夹。但是当我将它包装在 jar 文件中并发送给其他人时。每次我的朋友运行它时,它都会询问文件夹。我想知道如何让 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");
}
}
}