2013-06-27 4 views
0
protected static ResourceBundle bankBundle = ResourceBundle.getBundle("messages.EN.properties"); 

도트 (.) 확장 속성 이름을 사용하여 속성을 읽을 수 있습니까? 어떤 파일 확장자속성을 읽을 수 있습니까?

(주석에서 업데이트)

Properties prop = new Properties(); 
ClassLoader loader = Thread.currentThread().getContextClassLoader(); 
InputStream stream = loader.getResourceAsStream("/messages.EN.properties"); 
prop.load(stream); 
+0

* "더블은 인출 특성 이름을"또는 * "매우와의 무 비판적으로 좋아해야합니다" * 과거 시제? –

+0

ok @AndrewThompson이 나를 고쳐 주셔서 감사합니다. –

+0

나는 당신이 기존의 국제화보다 다른 어떤 의도를 가지고 있다고 확신하지만, 대회는 "messages_en.properties"(언어는 EN, 국가는 EN) 일 것입니다. –

답변

1

는 사실의 ResourceBundle 번들의 완전한 기본 이름을 수락 :

1

나는 당신이 자바의 속성 클래스를 사용한다고 생각합니다. 이 경우에는 다음과 같은 파일 번들을로드하려고 시도합니다.

messages/EN/properties.properties 
+0

속성 또는 속성? –

+0

roperties prop = 새 속성(); ClassLoader loader = Thread.currentThread(). getContextClassLoader(); InputStream stream = loader.getResourceAsStream ("/ messages.EN.properties"); prop.load (stream); – shrawan

+0

의견을 보내 주셔서 감사합니다. –

1

확실히 Properties 클래스를 사용할 수 있습니다.

http://docs.oracle.com/javase/6/docs/api/java/util/Properties.html

은 또한 당신이 코드 샘플을 참조 할 수 있습니다 : DYM를 '맹목적' '인용'으로 *

Properties prop = new Properties(); 
ClassLoader loader = Thread.currentThread().getContextClassLoader();   
InputStream stream = loader.getResourceAsStream("/messages.EN.properties"); 
prop.load(stream); 
관련 문제