有没有办法用Java启动流程?在.Net中,这可以通过例如:
System.Diagnostics.Process.Start("processname");
Java是否具有等效功能,因此我可以让用户找到该应用程序,然后将其用于任何OS?
http://www.rgagnon.com/javadetails/java-0014.html
import java.io.BufferedReader; import java.io.InputStreamReader; import java.nio.file.Paths; public class CmdExec { public static void main(String args[]) { try { // enter code here Process p = Runtime.getRuntime().exec( Paths.get(System.getenv("windir"), "system32", "tree.com /A").toString() ); // enter code here try(BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()))) { String line; while ((line = input.readLine()) != null) { System.out.println(line); } } } catch (Exception err) { err.printStackTrace(); } } }
你可以使用系统属性或类似方法获取本地路径。
http://download.oracle.com/javase/tutorial/essential/environment/sysprop.html