Desktop.getDeskto()。open(批处理文件)有时不起作用

时间:2014-07-31 04:32:06

标签: java windows batch-file apache-commons

我在以下代码中遇到两个问题

File export=new File("C:\\testdir"+jComboBox2.getSelectedItem().toString()+"\\export.bat");
try 
{
    FileUtils.write(export, "mini_server_11\\udrive\\bin\\mysqldump -u root -proot static_gatetest > C:\\testdir"+jComboBox2.getSelectedItem().toString()+"\\admin.sql", false);
} 
catch (IOException ex) 
{
    JOptionPane.showMessageDialog(this, "Unable to create file");
    Logger.getLogger(adminsetting.class.getName()).log(Level.SEVERE, null, ex);
    return;
}
//Execute bat file
try 
{
    Desktop.getDesktop().open(export);
} 
catch (IOException ex) 
{
    JOptionPane.showMessageDialog(this, "Unable to launch file");
    Logger.getLogger(adminsetting.class.getName()).log(Level.SEVERE, null, ex);
    return;
}
try 
{
    //Delete bat file. No worries. this file will be overwritten when next attempt
    //to build installer takes place
    FileUtils.forceDelete(export);
} 
catch (IOException ex) 
{
    Logger.getLogger(adminsetting.class.getName()).log(Level.SEVERE, null, ex);
}

我正在使用Apache Common IO来动态创建批处理文件。

  1. 第一个问题是Desktop.getdesktop.open()有时成功运行批处理文件,有时不运行。始终创建批处理文件,因为我可以看到cmd窗口。但它很快就退出了,而不是创建.sql文件。也没有例外。似乎批处理文件已创建,已打开但未执行。
  2. 第二个问题是,FileUtils.forceDelete总是引发异常。我不知道什么是错的。我在互联网上找到的所有手册。我也试过了deletequietly(),但它也说无法删除文件。
  3. 我对缩进问题表示歉意。我仍然无法弄清楚如何在SO中正确编写代码

0 个答案:

没有答案
相关问题