Here are three ways to open
/**
* Open With Java.awt.Desktop
* @see Open Directory or file name allows spaces to be included
*/
private static void Useawtdesktop () throws ioexception{
Desktop.getdesktop (). Open (New File ("d:/my local/test case. xls"));
}
/**
* Open with cmd command
* @see wps text--------runtime.getruntime (). EXEC ("cmd/c start wps")
* @see wps form--------runtime.getruntime (). EXEC ("cmd/c start et")
* @see WPS Demo--------Runtime.getruntime (). EXEC ("cmd/c start WPP")
* @see Office Word---runtime.getruntime (). EXEC ("cmd/c start Winword")
* @see Office Excel--runtime.getruntime (). EXEC ("cmd/c start Excel")
*/
private static void Usecmdcommand () throws ioexception{
If you open a directory or file name that does not contain spaces, use the following method
Runtime.getruntime (). EXEC ("cmd/c start d:/mylocal/test case. xls");
(Can ' run ' or ' win+r ', then enter ' cmd/? ') View Help information)
Runtime.getruntime (). EXEC (new string[]{"cmd.exe", "/C", "d:/my local/test case. xls"});
}
/**
* Open with Local Setup program
* @see If you open a directory or file name that contains spaces, it will do nothing. However, the local program's installation directory allows spaces
*/
private static void Uselocalcommand () throws ioexception{
String Etcommand = "D:/program Files/wps/8.1.0.3526/office6/et.exe";
String FilePath = "d:/mylocal/test case. xls";
Runtime.getruntime (). EXEC (Etcommand + "" + FilePath);
}
}
Open a local file in Java