您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息
三六零分类信息网 > 昌都分类信息网,免费分类信息发布

怎样用java编程来打开电脑中已经安装的应用程序?

2022/10/30 22:00:29发布38次查看
runtime类中有个exec方法,把行文件的路径以字的方式放到该方法中,就能在线程中打个可执行文件了。注意runtime是单例模式,没有构造函数,只有生成实例的静态方法。部分代码如下:思必达学院可以到网站了解下,如果您需要的话,可以咨询客服,专业人士为您解答,解决您的问题!!
classrundemo{
publicstaticvoid main(string []args) {
runtime rt=runtime.getruntime();
rt.exec("d:\lol\lol.exe");//该路径是可执行文件的路径
}
}
如有疑惑,欢迎追问!!
到.exe的路,给你个例看
string path = "notepad.exe"; //(c:\program files\tencent\qq\bin\qq.exe)
try {
runtime runtime = runtime.getruntime();
process process = runtime.exec(path);
} catch (ioexception e) {
e.printstacktrace();
}
记事本,是windows自,qq是你自己安装的,你要写绝对路径
windows电脑中安装的应用均是由的c++、c#和c系统编程语言开,安卓的也都是c/s(客户端/服务器)程序。
java的可以是b/s(浏览器/服务器)程序,如web项目,也可以开发android程序,但是是安装在安卓手机中的。
综上,java编程无法打开电脑中已经安装的应用程序。
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
final class deskdemo extends jframe {
public string gettitle() {return "deskdemo";}
static private final dimension size = new dimension(600,400);
public dimension getpreferredsize() {return size;}
public dimension getmaximumsize() {return size;}
public dimension getminimumsize() {return size;}
public dimension getsize(){return size;}
private class demoshowaction extends abstractaction{
private jfilechooser filechooser;
private demoshowaction() {
super("show desk support");
filechooser=new jfilechooser(".");
}
public void actionperformed(actionevent e) {
if(jfilechooser.approve_option==filechooser.showopendialog((component) e.getsource())){
if(desktop.isdesktopsupported()){
joptionpane.showmessagedialog(null, "你的环境不 desktop", "desktop运行环境", joptionpane.error_message);
return;
}
file file=filechooser.getselectedfile();
if(file!=null){
try {
desktop.getdesktop().open(file);
} catch (ioexception e1) {
e1.printstacktrace();
}
}
}
}
}
deskdemo() throws headlessexception {
attachlisteners();
dolay();
}
private void attachlisteners(){
setdefaultcloseoperation(jframe.exit_on_close);
}
private void dolay(){
container container = getcontentpane();
container.add(new jbutton(new demoshowaction()),borderlayout.north);
pack();
setvisible(true);
}
public static void main(string[] args) {
system.setproperty("swing.defaultlaf","com.sun.java.swing.plaf.windows.windowslookandfeel");
swingutilities.invokelater(
new runnable(){
public void run() {
new deskdemo();
}
}
);
}
}
java中的runtime可以调用系统命令,自然就可以了。
昌都分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录