Reputation: 33
I need a java code to allow me to run this notepad and open a specified file, for example :
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
.
What can be the problem ?
Upvotes: 0
Views: 80
Reputation: 159844
The second argument in exec
represents the environmental variables. You want
String[] a = { "notepad", "C:/Users/day/Desktop/a.txt" };
Process p = Runtime.getRuntime().exec(a);
Upvotes: 2
Reputation: 3660
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);
Upvotes: 0