到目前为止我所做的是:
/** Default location of help files folder */
private static final String DEFAULT_PATH = "../../../../resources/files/help/";
/** A 404 error file */
private static final String ERROR_404 = "../../../../resources/files/help/404.html";
/**
* @param fileName
* @return The URL of file, if found at default location, otherwise a 404 error page URL.
*/
public static URL getURL(String fileName) throws MalformedURLException{
URL url = (new File(ERROR_404)).toURI().toURL();
System.out.println(url);
url = (new File(DEFAULT_PATH + fileName)).toURI().toURL();
System.out.println(url);
return url;
}
输出:
文件:/H:/My%20Project/Project%20Name%20Module/../../../../resources/files/help/404.html 文件:/H:/My%20Project/Project%20Name %20Module/../../../../resources/files/help/plazaCode.html
通过 NetBeans 创建的 JAR 中的文件夹层次结构:
我在 Windows 7,JDK 7 上。
更新:
实际上,我希望通过以下URL
方法JTextPane
显示 HTML 页面:
textPane.setPage(URL url);
我能有比这更好的解决方案吗?并具有相同的文件夹层次结构..?