「java中调用exe程序」java 执行exe
本篇文章给大家谈谈java中调用exe程序,以及java 执行exe对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
如何使用java调用本地EXE程序
最近用到在java中调用本地的一个程序,是windows中的exe格式的程序,利用神奇的互联网找到了解决的方法,发现异常简单的几句代码就可以实现 见代码:[*]package com.java.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:/Notepad2/Notepad2.exe "","d:/EntPartner_2.xml"});[*]System.out.println("成功打开软件和文件!
java如何调用exe文件?
public class transferExe {\x0d\x0a public static void main(String[] args) {\x0d\x0a openWinExe();\x0d\x0a openExe();\x0d\x0a }\x0d\x0a //用 Java 调用windows系统的exe文件,比如notepad,calc之类\x0d\x0a public static void openWinExe() {\x0d\x0a Runtime rn = Runtime.getRuntime();\x0d\x0a Process p = null;\x0d\x0a try {\x0d\x0a String command = "notepad";\x0d\x0a p = rn.exec(command);\x0d\x0a } catch (Exception e) {\x0d\x0a System.out.println("Error win exec!");\x0d\x0a }\x0d\x0a }\x0d\x0a //调用其他的可执行文件,例如:自己制作的exe,或是 下载 安装的软件.\x0d\x0a public static void openExe() {\x0d\x0a Runtime rn = Runtime.getRuntime();\x0d\x0a Process p = null;\x0d\x0a try {\x0d\x0a p = rn.exec("\"D:/QQ2010.exe\"");\x0d\x0a } catch (Exception e) {\x0d\x0a System.out.println("Error exec!");\x0d\x0a }\x0d\x0a }\x0d\x0a }
怎样在java类中调用带参数的可执行文件(比如:.exe,.sh等等)?
比如调用exe程序"java -version":
String[] cmd = new String[] {"java", "-version"};
Process process = Runtime.getRuntime().exec(cmd);
BufferedReader r = new BufferedReader(new InputStreamReader(process.getErrorStream()));
String l = null;
while((l = r.readLine()) != null) {
System.out.println(l);
}
Process有两个流可以读取外部程序的标准输出(就是运行结果啦),一个是getInputStream,一个是getErrorStream。
如果要调用C或C++动态链接库中的函数的话,就要复杂一些,要用到JNI了。
恳求在java中调用exe文件的与源代码
java.lang.Runtime
Process exec(String command)
Executes the specified string command in a separate process.
Process exec(String[] cmdarray)
Executes the specified command and arguments in a separate process.
Process exec(String[] cmdarray, String[] envp)
Executes the specified command and arguments in a separate process with the specified environment.
Process exec(String[] cmdarray, String[] envp, File dir)
Executes the specified command and arguments in a separate process with the specified environment and working directory.
Process exec(String command, String[] envp)
Executes the specified string command in a separate process with the specified environment.
Process exec(String command, String[] envp, File dir)
Executes the specified string command in a separate process with the specified environment and working directory.
关于java中调用exe程序和java 执行exe的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。