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

前端 未结 5 1127
深忆病人
深忆病人 2021-01-04 09:08

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

5条回答
  •  盖世英雄少女心
    2021-01-04 09:48

    I've done some investigation on this item here - note that opening cmd and typing start file:///c:/temp/test.html#anchor also doesn't work.

    I think the only thing that actually works is to call a browser manually (or use a third-party tool that does this).

    On Windows, you always have Internet Explorer, so you could call Runtime.getRuntime().exec("cmd.exe start iexplore " + myURL) if you really don't want to find iexplore.exe yourself - but this doesn't always work either.

提交回复
热议问题