The solution is to find the absolute path to url1.html to make a java.io.File object on it, and then use the combination toURI().toURL() :
URL url1 = (new java.io.File(absolutePathToHTMLFile)).toURI().toURL();
Assuming the current directory is the root of the page , you can pass the relative path to the File :
URL url1 = (new java.io.File("page/url1.html")).toURI().toURL();
or
URL url1 = (new java.io.File(new java.io.File("page"), "url1.html")).toURI().toURL();
But it will depend on where you start the application from. I would do this by taking the root directory as a command line argument if it is the only custom option for the application or from the configuration file, if any.
Another solution is to place the html file as a resource in your application's jar file.
source share