0

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 ?

1

2 Answers 2

2

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);
Sign up to request clarification or add additional context in comments.

Comments

0

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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.