It is necessary for the program to open the html file:

import java.awt.*; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; public class Main { public static void main(String args[]) { Desktop desktop = Desktop.getDesktop(); try { URI url = new URI("D:\\3 泻褍褉褋\\袘袚校袠袪(谢斜)\\小懈袗孝邪褉懈小\\袥斜5\\2\\lb5\\src\\html\\lb5.html"); desktop.browse(url); } catch (URISyntaxException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } 

How to make sure that the file was opened?

    2 answers 2

    Try this:

     File file = new File("D:\\3 泻褍褉褋\\袘袚校袠袪(谢斜)\\小懈袗孝邪褉懈小\\袥斜5\\2\\lb5\\src\\html\\lb5.html"); URI url = file.toURI(); 

    or simply:

     URI url = new URI("file:///[file_path]"); 

    where [file_path] is the path to the file.

        Desktop desktop = Desktop.getDesktop(); File f = new File("D:\\3 泻褍褉褋\\袘袚校袠袪(谢斜)\\小懈袗孝邪褉懈小\\袥斜5\\3\\lb5\\src\\main\\webapp\\index.jsp"); desktop.browse(f.toURI()); 
      • Did the file change solve your problem? If so, how? Try to write more detailed answers. - Zufir