我想制作一个简单的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");
}
}
}
将其保存在配置文件中。如果配置文件存在,请阅读路径。如果没有,请询问并保存。 – m0skit0
如何添加一些if语句,如果它是空的,我想让执行那个JOpitionPane.showInputDialog。如果它不是空的,那么我不执行输入对话框。 –