i got two questions.
Where is the directory the Method Runtime.getRuntime().exec() gets its resources from?
if i am calling Runtime.getRuntime().exec("notepad.exe"), why does it start the windows editor? Where does java gets the .exe source from?
based on this question, i have to let the user choose, if he wants to open a file in an editor, which editors he prefers, and wants to use. He only writes in something like notepad.exe or ultraedit.exe and the choosen file will be opened in the editor written down here. At the moment, i am opening a file with this Method
public void open(String path) {
try {
if(new File(path).exists())
Runtime.getRuntime().exec("notepad.exe " + path);
} catch (IOException e) {
e.printStackTrace();
}
}
So as you can see every file will be opened within the notepad. But i need to have something like this :
public void open(String program, String path) {
try {
if(new File(path).exists())
Runtime.getRuntime().exec(program + " " + path);
} catch (IOException e) {
e.printStackTrace();
}
}
So is there any possibility to open txt files in different editors, by just calling their
.exe file?
Its not about java. check the
PATHenvironment variables in you Operating systems. It has the path for all the exe files.Try this
1) open cmd
2) type
c:\> echo %PATH%the second will tell you the values of PATH variable
yes edit the PATH variable to include the path of you other editor’s exe file ( use semicolon and then append the path to environment don’t replace the existing string ), and the java program remains the same