2012-01-06 5 views
2

애플릿에 익숙하지 않아서 리소스로 jar 파일을 내보낼 필요가 없습니다.애플릿의 등록 정보 파일로드

브라우저는 특성 파일을로드 실패 :

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

속성 파일에는로 가져옵니다 :

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

답변

4

enter image description here

코드는 속성 파일을로드 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 = connection.getInputStream(); ' – MyTitle

+0

@MyTitle 팁 주셔서 감사합니다. :) –