Java 无法执行批处理文件

Java 无法执行批处理文件,java,batch-file,cmd,Java,Batch File,Cmd,我有这组java代码: public class OpenBatchFile { public OpenBatchFile() { super(); } /**Main Method * @param args */ public static void main(String[] args) { //Get Runtime object Runtime runtime = Runtime.getRuntime(); try { //Pass

我有这组java代码:

public class OpenBatchFile {
public OpenBatchFile() {
    super();
}

/**Main Method
 * @param args
 */
public static void main(String[] args) {
    //Get Runtime object
    Runtime runtime = Runtime.getRuntime();
    try {
        //Pass string in this format to open Batch file
        runtime.exec("cmd /c start Desktop:\\OpenNotepad.bat");
    } catch (IOException e) {
        System.out.println(e);
    }
  }
}
当我在cmd上键入
start Desktop:\\OpenNotepad.bat
命令时,访问被拒绝。我得到一个错误声明:

没有与执行请求的操作相关联的程序。请安装程序,或者,如果已经安装了程序,请在“默认程序”控制面板中创建关联


要执行OpenNotepad.bat文件,我必须在代码中添加什么?有人请帮帮我。非常感谢。

cmd
中,没有什么比得上
桌面:\\OpenNotepad.bat
。您可能想要:

start "" "%desktop%\OpenNotepad.bat"
给定定义了
%desktop%
。如果没有,请使用

start "" "%homepath%\desktop\OpenNotepad.bat"
或者只是

"%desktop%\OpenNotepad.bat"

试用

%UserProfile%\Desktop\

请考虑。它是一个健壮可靠的库,可以从java应用程序执行外部应用程序。
"%homepath%\desktop\OpenNotepad.bat"