0

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?

4
  • 2
    Desktop.getDesktop().open(file); Commented Nov 17, 2014 at 18:04
  • Failed to work... wouldnt accept a file name as a string or as a param Commented Nov 17, 2014 at 18:06
  • 1
    Runtime.getRuntime().exec("notepad.exe"); Commented Nov 17, 2014 at 18:06
  • @SAXTEN2011 its a File class. File file = new File (String path); Commented Nov 17, 2014 at 18:28

1 Answer 1

2

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

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.