[英]Java code to run applications
I need a java code to allow me to run this notepad and open a specified file, for example : 我需要一个java代码来允许我运行这个记事本并打开一个指定的文件,例如:
String []a={"C:/Users/day/Desktop/a.txt"};
Process p = Runtime.getRuntime().exec("notepad",a);
This code runs notepad but does not open the file a.txt
. 此代码运行记事本但不打开文件
a.txt
。
What can be the problem ? 可能是什么问题?
You need double slashes in your file name, and all of your command args can be in the same array. 您的文件名中需要双斜杠,并且所有命令参数都可以在同一个数组中。
String[] args = {"notepad.exe", "C://Users//day//Desktop//a.txt"};
Process p = Runtime.getRuntime().exec(args);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.