Java 无法执行文件名包含多个空格作为参数的windows命令行命令

Java 无法执行文件名包含多个空格作为参数的windows命令行命令,java,windows,filenames,executable,Java,Windows,Filenames,Executable,我正在尝试使用带有所有绝对路径的参数执行pdf2html。相同的命令在命令提示符下运行良好,但通过java发出错误。下面是我正在使用的代码片段 String command = pdf2html5ex_file_path + " --decompose-ligature 1 --tounicode 1 \"" + _curr_pdf_file.getAbsolutePath() +

我正在尝试使用带有所有绝对路径的参数执行pdf2html。相同的命令在命令提示符下运行良好,但通过java发出错误。下面是我正在使用的代码片段

String command = pdf2html5ex_file_path + 
                    " --decompose-ligature 1 --tounicode 1 \""  + 
                    _curr_pdf_file.getAbsolutePath() + 
                    "\" \"" + 
                    _input_html_file_name + 
                    "\" --dest-dir \"" + 
                    removeEnd(_input_html_folder_path,"\\") + 
                    "\" ";
String Perms = _curr_pdf_file.canRead()?"Readable":"Non-Readable";
Perms += ";"+ (_curr_pdf_file.canWrite()?"Writable":"Non-Writable");
Perms += ";"+ (_curr_pdf_file.canExecute()?"Executable":"Non-Executable");
System.out.println("Permissions : "+Perms);
System.out.println("Command: "+command);
Runtime runtime = Runtime.getRuntime();
// Execute command
Process process = runtime.exec(command);
异常消息:

Permissions : Readable;Writable;Executable
Command: E:\BackUpDisk\eTextCo\PDFBOX\WorkSpace\libs\pdf2htmlEX\pdf2htmlEX.exe --decompose-ligature 1 --tounicode 1 "E:\BackUpDisk\eTextCo\bookpad\Process\1\input\pdf\TM  11.pdf" "TM  11.html" --dest-dir "E:\BackUpDisk\eTextCo\bookpad\Process\1\input\html" 
I/O Error: Couldn't open file 'E:\BackUpDisk\eTextCo\bookpad\Process\1\input\pdf\TM 11.pdf': File exists.
Error: Cannot read the file
Parsing completed for : TM  11.html
Unable to process record E:\BackUpDisk\eTextCo\bookpad\Process\1\input\pdf\TM  11.pdf
java.io.FileNotFoundException: E:\BackUpDisk\eTextCo\bookpad\Process\1\input\html\TM  11.html (The system cannot find the file specified)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(Unknown Source)
    at org.jsoup.helper.DataUtil.load(DataUtil.java:37)
    at org.jsoup.Jsoup.parse(Jsoup.java:88)
    at Parser.pdf2html(Parser.java:213)
    at Parser.main(Parser.java:33)
在上面的输出中,尝试打印将要执行的命令,该命令将正确的文件路径显示为字符串,但第二行显示无法读取路径错误的文件,其中没有两个空格


有人能解释一下这里发生了什么吗?

错误显示FileAlReadyExistException:E:\BackUpDisk\eTextCo\bookpad\Process\1\unprocessed\pdf\TM 11.pdf,即使打印的命令中没有提到这个名称,这很奇怪。另外,您最好使用Runtime.exec版本,该版本接受字符串数组,以便为您转义参数。您应该使用ProcessBuilder,这样传递包含空格的参数就容易多了