2012-01-06 20 views
2

アプレットについては初めて、リソースをjarにエクスポートする必要はありませんでした。アプレットでのプロパティファイルの読み込み

ブラウザは、プロパティファイルをロードするために失敗している:プロパティファイルをロードする

enter image description here

コード:

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

プロパティファイルはようにインポートされ

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

答えて

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); 
+1

デフォルトのタイムアウトは無限大ですので、実際には 'openStream()'を使うのはお勧めできません。私はこのようにすることを好む方法を聞いた: \t \t 'URL d =新しいURL(" "); \t \t URLConnection connection = d.openConnection(); \t \t connection.setConnectTimeout(5000); \t \t InputStream is = connection.getInputStream(); ' – MyTitle

+0

@MyTitleヒントをお願いします。 :) –

関連する問題