2

I have written a java script whose work is to open URL's mentioned in the text file and it should repeat this process continuously but the problem is as soon as it reads the new URL mention in next line of text file it opens that URL in new tab but I want to open all the URL's in same tab of chrome browser.

Code what I have written:

while(true){ 
    BufferedReader buf = new BufferedReader(new FileReader("C:\\link.txt"));
    String currentLine = null;
    while((currentLine = buf.readLine())!=null){
        System.out.print(currentLine+"\n");
         Desktop.getDesktop().browse(new URL(currentLine).toURI());
         Thread.sleep(10000);
    }
    }
}

Is there any other option then Desktop.getDesktop() that will also work

My text file has two links like this:

https://www.google.co.in/?gfe_rd=cr&ei=y8a_WPTUFLOl8weF8bK4DQ
https://in.yahoo.com/

How to open them in same tab?

Srishti
  • 355
  • 1
  • 17
  • Possible duplicate of [Can Java's Desktop.browse provide an HTML Target in order to reuse a browser window?](http://stackoverflow.com/questions/8761198/can-javas-desktop-browse-provide-an-html-target-in-order-to-reuse-a-browser-win) – anacron Mar 08 '17 at 09:45
  • is there any way out for the above mentioned problem ..!!! – Srishti Mar 08 '17 at 10:11
  • Can you use one HTML page to show those links? In that case you can open that HTML page and provide links to these two pages with a common HTML `target`. So, both will open in the same tab. – anacron Mar 08 '17 at 10:17
  • how to do that in java – Srishti Mar 08 '17 at 10:25
  • `Desktop.getDesktop().browse(new URL("file://C/path/to/html/file.html").toURI());` - This will open the HTML file in the browser. That in turn will contain links to the two pages that you mentioned. – anacron Mar 08 '17 at 10:28

1 Answers1

0
 Desktop.getDesktop().browse()

Does NOT support this, as seen in Can Java's Desktop.browse provide an HTML Target in order to reuse a browser window?

Though, alternatives for this are the use of Process as seen in

Process oProc = Runtime.getRuntime().exec( currentLine );

And then make use of this process to send more commands to.

Or make use of a library / API such as Browserlaunch

The issue with Chrome, however is that Chrome likes to open new tabs in a new screen. If you hit ctrl + N (new tab on a lot of browsers) on Chrome, it'll open up a new screen instead

Community
  • 1
  • 1