0

i want to open multiple websites in IE using java program.

here is the code the websites are fetched from txt file

while((line = br.readLine()) != null)
    {
        StringTokenizer webLink = new StringTokenizer(line,";");
        while(webLink.hasMoreTokens())
            {   
                    String webPathString = webLink.nextToken();
                    System.out.println(webPathString);
                    Desktop desktop = Desktop.getDesktop(); 
                    desktop.browse(new URI(webPathString));
            }
    }

problem is only last site is getting opened in a browser insted of all.

taufik
  • 25
  • 6
  • 3
    _Please provide data of your text file._ – akash Oct 14 '14 at 07:36
  • have you tried introducing sleep()s? have you tried from multiple threads? – radai Oct 14 '14 at 07:36
  • Note that your current code will open the URL in the user's preferred browser. *This is a good thing*, but I just wanted to point out it won't always be IE. – Duncan Jones Oct 14 '14 at 07:41
  • Have you confirmed that this code is actually run more than once (i.e. that while loop happens the expected amount of times)? – Deltharis Oct 14 '14 at 07:41
  • Two consecutive calls to `desktop.browse` will work as expected, so the issue has to be related to how you obtain that list of URLs. There's not enough info in your question to help you there, so I'm voting to close. – Duncan Jones Oct 14 '14 at 07:45

1 Answers1

-1

desktop.browse will open all links in a current window only

For more details check the below discussion

Can Java's Desktop library launch a URL in a new Browser Tab or Window?

Community
  • 1
  • 1
Gnanz
  • 1,833
  • 5
  • 24
  • 51