简体   繁体   English

在小程序中加载属性文件

[英]Loading Properties files in an applet

New to Applets, I have never dealt with having to export the resources to the jar. Applets的新手,我从未处理过将资源导出到jar的问题。

The browser is failing to load properties files: 浏览器无法加载属性文件:

access denied ("java.io.FilePermission"
"config\en-us.properties""read")

Properties files are imported as so: 属性文件的导入方式如下:

在此处输入图片说明

Code to load Properties file: 加载属性文件的代码:

prop.load(new FileInputStream("config/en-us.properties"));

Obtain an URL to the properties file in the jar using: 使用以下命令获取jar中属性文件的URL:

URL urlToProps = this.getClass().getResource("/config/en-us.properties");

Use an URLConnection to set a read timeout. 使用URLConnection设置读取超时。

// courtesy of MyTitle 'default timeout is infinity'
URLConnection connection = urlToProps.openConnection(); 
connection.setConnectTimeout(5000); 

Get an InputStream . 获取一个InputStream

InputStream is = connection.getInputStream();

Then use Properties.load(InputStream) to load it. 然后使用Properties.load(InputStream)加载它。

prop.load(is);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM