Applets新手,我从未处理过将资源导出到jar的问题。
浏览器无法加载属性文件:
access denied ("java.io.FilePermission"
"config\en-us.properties""read")
属性文件导入如下:
加载属性文件的代码:
prop.load(new FileInputStream("config/en-us.properties"));
答案 0 :(得分:4)
使用以下方法获取jar中属性文件的URL:
URL urlToProps = this.getClass().getResource("/config/en-us.properties");
使用URLConnection
设置读取超时。
// courtesy of MyTitle 'default timeout is infinity'
URLConnection connection = urlToProps.openConnection();
connection.setConnectTimeout(5000);
获取InputStream
。
InputStream is = connection.getInputStream();
然后使用Properties.load(InputStream)
加载它。
prop.load(is);