Open a local file in Java

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.