Author: Chen Gang, Guilin, 97, graduated from the Department of Mathematics, Guangxi Normal University, temporarily at IBM China Research Center, a part-time engaged in software development, focus on java platform software development (2004.2-?). Email: Glchengang@hotmail.com blog: Glchengang.yeah.net Recently develops report modules, after generating report files (an Excel file) to play this file. Very simple, use Java to call external programs. code show as below:
String path = "C: / Report _20040504.xls"; try {// is equivalent to "start" -> "Run" effect runtime.getRuntime (). EXEC ("cmd / c start" path); } catch (ioException e) {E.printStackTrace ();
However, if the method of the file contains a space above the space is wrong. Going to Google, no, no, see CMD /? Help, I have not, I have tried many times, I found that the solution is actually very simple, it is ignorant. The code is as follows, no need to say.
String path = "c: / documents and settings / giles / desktop / report _20040504.xls"; try {runtime.getRuntime (). EXEC ("cmd / c start excel /" path "/"); } catch (ioException e) {E.printStackTrace ();