2

This is my code. I am able to open browser but it will not load the html source.

class Browser {
    public static void main(String[]args) {
        try {
            Runtime rtime = Runtime.getRuntime();

            String url = "‪C:/Program Files (x86)/Internet Explorer/DD.html";
            String brow = "C:/Program Files (x86)/Internet   Explorer/iexplore.exe";

            Process pc = rtime.exec(brow + url);    
            pc.waitFor();       
         } catch (Exception e) {
              System.out.println("\n\n" + e.getMessage());
         }
    }
}
3
  • stackoverflow.com/questions/20517434/… Commented May 2, 2015 at 3:16
  • is your DD.html really in the the Internet Explorer program directory? You shouldn't really be changing anything in there Commented May 2, 2015 at 10:23
  • Yes it is in the internet explorer program directory and i got my answer ,thanks for showing your interest Commented Jul 2, 2015 at 18:13

2 Answers 2

5

Use this:

Desktop.getDesktop().browse(URI);
Sign up to request clarification or add additional context in comments.

Comments

0

You have too many spaces in the brow value - I presume that's just a formatting issue in the question.

Using the single-argument version of exec splits the input string by spaces, so your code will try to execute a command C:/Program and pass it arguments "Files", "(x86)/Internet", "Explorer/iexplore.exeC:/Program", "Files", etc.

Note that "Explorer/iexplore.exeC:/Program" - because you concatenated the two strings without a space.

You could resolve these issues by passing an array of strings to exec() instead of using the single-string version, but you're better off using Desktop.getDesktop().browse(URI);

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.