我最近为我的应用程序开发了一个 GUI,它在 Linux Ubuntu 10.04 上运行 shell 脚本。直到今天它工作正常。我设计了一个按钮,单击该按钮将打开选择文件的提示。JFileChooser 用于操作。但是从今天早上开始,没有任何错误,单击该按钮不会执行任何操作。它不只是突然工作。这是什么错误?有人可以帮忙吗?这是与安装的 OS/Java 相关的任何错误吗?
提前致谢。
int yorn = JOptionPane.YES_OPTION;
String user = System.getProperty("user.home");
File file = new File(user+"/.afile");
if (file.exists()){
yorn = JOptionPane.showConfirmDialog(this,"There seem to have a Previous project , Do you want to back up??");
if (yorn == JOptionPane.YES_OPTION){ // yesoption clicked!
//choose folder to open!
JFileChooser jf = new JFileChooser();
jf.setDialogTitle("Back up location?");
String pathname = null;
jf.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
jf.showOpenDialog(null);
File f = jf.getSelectedFile();
pathname = f.getAbsolutePath();
// JOptionPane.showMessageDialog(this,pathname);
try{
Process copy = Runtime.getRuntime().exec("sh "+user+"/myprojects/.backup.sh "+pathname);
}
catch(Exception e){
JOptionPane.showMessageDialog(this, e);
}
//open file for analysing..
JOptionPane.showMessageDialog(this,"Backing up complete.. ");
JFileChooser jf2 = new JFileChooser();
jf2.setDialogTitle("Open the Codebase");
String pathname2 = null;
jf2.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
jf2.showOpenDialog(null);
File f2 = jf2.getSelectedFile();
pathname2 = f2.getAbsolutePath();
String username = System.getProperty("user.home");
File writefile = new File(username+"/.afile");
Writer output = null;
try {
output = new BufferedWriter(new FileWriter(writefile));
output.write(pathname2);
output.close();
// JOptionPane.showMessageDialog(this,username);
} catch (IOException ex) {
Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
}
} else if (yorn == JOptionPane.NO_OPTION){
JFileChooser jf = new JFileChooser();
jf.setDialogTitle("Open the Codebase");
String pathname = null;
jf.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
jf.showOpenDialog(null);
File f = jf.getSelectedFile();
pathname = f.getAbsolutePath();
String username = System.getProperty("user.home");
File writefile = new File(username+"/.afile");
Writer output = null;
try {
output = new BufferedWriter(new FileWriter(writefile));
output.write(pathname);
output.close();
// JOptionPane.showMessageDialog(this,username);
} catch (IOException ex) {
Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
这是代码。它的作用是检查文件是否存在,如果存在,则提示进行备份。如果备份是,则备份并打开一个新窗口以进行另一个选择,如果备份是否,则打开文件选择。正如我所提到的,这一直有效,直到我问这个问题。它突然停止工作。感谢所有的答复。