Reputation: 3
I'm looking to create a desktop helper program with Java, a couple JOptionPane
option dialogues, and in that I would like to open programs (both internal and external, internal being something like notepad, external being a game like league of legends, something that doesn't come with Windows if that makes any sense whatsoever) I also want to open webpages, but I've got that worked out with this code:
try {
Desktop.getDesktop().browse(new URI("http://www.gamestop.com/wii-u/games/super-smash-bros/114504"));
giftinfo();
} catch (IOException e) {
e.printStackTrace();
} catch (URISyntaxException e) {
e.printStackTrace();
}
Is there a way to open other (non Java) programs from a Java program?
Upvotes: 0
Views: 263
Reputation: 6816
Is short, yes you can open every inbuilt application has a command that it can be ran from run command window. Here is an example for opening notepad.
public static void main(String[] args) {
try {
System.out.println("Notepad Opening");
Runtime runTime = Runtime.getRuntime();
Process process = runTime.exec("notepad");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Notepad Closing");
process.destroy();
} catch (IOException e) {
e.printStackTrace();
}
}
Upvotes: 2