Home > Java > JavaBase > body text

How to open exe file in java

王林
Release: 2019-12-04 14:49:52
Original
2958 people have browsed it

How to open exe file in java

函数介绍:

Runtime 类代表着Java程序的运行时环境,每个Java程序都有一个Runtime实例,该类会被自动创建,我们可以通过Runtime.getRuntime() 方法来获取当前程序的Runtime实例。

java视频教程推荐:java免费视频教程

示例如下:

package com.test;
public class OpenExe {
	/**[*]* @param args[*]*/
	public static void main(String[] args) 
	{
		Runtime rt = Runtime.getRuntime();
		Process p = null;
		try
		{
		    //执行的文件的位置
			p =rt.exec(new String[]{"D:\\qq\\qq.exe"});
			System.out.println("成功打开软件和文件!");
		}catch (Exception e) {
			System.out.println("打开软件失败");
			e.printStackTrace();			
		}
		}
}
Copy after login

相关文章教程推荐:java编程入门

The above is the detailed content of How to open exe file in java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template