How to launch a file protocol URL with an anchor from Java?

Posted by Jeff C on Stack Overflow See other posts from Stack Overflow or by Jeff C
Published on 2008-11-18T23:12:58Z Indexed on 2010/03/09 3:06 UTC
Read the original article Hit count: 364

Filed under:
|
|
|

From a Java program, I need to launch the default browser on a local HTML file, pointed to an anchor inside the file. In Java SE 6, the java.awt.Desktop.browse method will open the file, but will not honor the anchor, so something like the following opens the file at the top, but does not page the browser to the anchor:

Desktop.getDesktop("file:///C:/foo/bar.html#anchor");

Sun says here http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6477862 that anchors are not supported in the file URI protocol.

Does anyone have a better answer?

I can use Java SE 6. I would be OK with a Windows only solution.

© Stack Overflow or respective owner

Related posts about java

Related posts about uri