Java use the DOS command to open the file path contains spaces

Recommended for you: Get network issues from WhatsUp Gold. Not end users.
A, in the DOS window, open the file (path contains an empty , and path does not contain a null , the method is as follows: (open the d:\aa a\bb b.xlsx files, folders and files were AA a BB b.xlsx contain empty)
Method: open the path contains the empty , Command: C:\Users\Administrator> start " " " d:\aa a\bb b.xlsx" (command line is: the start plus two double quotation marks, Coupled with the use of double quotes path file name, The focus is: start must keep up with a pair of double quotes, Path of the file name must be enclosed in double quotes, Not a single one can be omitted, But the path to the file before the double quotation marks must not and start after the second quotation marks to get together, At least one empty apart from , This method not only can open the path, file name contains a space of , But can be opened without air of , Can replace the method of two)
Method two: open the path to the file does not contain names;, the command: C:\Users\Administrator> start d:\aaa\bbb.xlsx (command line: start plus path file name, the focus is: this way can only open a path, the file name does not contain the empty file)
B, implemented in Java as follows:
//With an empty  file path and file name;
String path = "d:\\aa a\\bb b.xlsx";
//The implementation of the DOS command line, the "CMD /c" at the beginning //Note: second \" third \" must have an empty , otherwise fail; String command = "cmd /c start " + "\"\" \"" +path+"\"";
//Using process to call DOS command to open file Process proc = Runtime.getRuntime().exec(command);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Esther at November 26, 2013 - 2:44 PM