
ResourceBundle 클래스의 create 메서드는 리소스 파일을 읽어들이기 위한 메서드입니다.
InputStream 객체를 넘기면, 해당 객체가 가리키는 리소스 파일을 읽어들입니다.
리소스 파일은 properties나 XML 형식으로 작성된 파일이어야 합니다.
create 메서드의 파라미터 중 하나인 "name"은 리소스 파일의 이름을 지정합니다.
이름을 지정하지 않으면, create 메서드는 리소스 파일을 찾지 못하고 Exception을 발생시킵니다.
create 메서드의 파라미터 중 하나인 "locale"은 리소스 파일의 지역 설정을 지정합니다.
지역 설정을 지정하지 않으면, create 메서드는 기본 지역 설정을 사용합니다.
create 메서드의 파라미터 중 하나인 "ClassLoader"은 리소스 파일을 찾을 때 사용할 클래스 로더를 지정합니다.
클래스 로더를 지정하지 않으면, create 메서드는 기본 클래스 로더를 사용합니다.
예를 들어, properties 파일을 읽어들이기 위해 create 메서드를 호출할 수 있습니다.
#hostingforum.kr
java
ResourceBundle bundle = ResourceBundle.getBundle("myResources", Locale.KOREA);
이 코드는 "myResources.properties" 파일을 읽어들입니다.
만약 InputStream 객체를 넘기면, 다음과 같이 코드를 작성할 수 있습니다.
#hostingforum.kr
java
InputStream inputStream = getClass().getResourceAsStream("/myResources.properties");
ResourceBundle bundle = ResourceBundle.getBundle("", new PropertiesReader(inputStream));
이 코드는 InputStream 객체를 통해 "myResources.properties" 파일을 읽어들입니다.
PropertiesReader 클래스는 InputStream 객체를 통해 properties 파일을 읽어들이는 클래스입니다.
#hostingforum.kr
java
public class PropertiesReader extends Properties {
public PropertiesReader(InputStream inputStream) {
try {
load(inputStream);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
이 클래스는 InputStream 객체를 통해 properties 파일을 읽어들이고, Properties 객체를 반환합니다.
create 메서드의 파라미터 중 하나인 "ClassLoader"을 지정하지 않으면, create 메서드는 기본 클래스 로더를 사용합니다.
만약 클래스 로더를 지정하고 싶다면, 다음과 같이 코드를 작성할 수 있습니다.
#hostingforum.kr
java
ClassLoader classLoader = getClass().getClassLoader();
ResourceBundle bundle = ResourceBundle.getBundle("", new PropertiesReader(inputStream), classLoader);
이 코드는 클래스 로더를 지정하고, InputStream 객체를 통해 "myResources.properties" 파일을 읽어들입니다.
create 메서드의 파라미터 중 하나인 "locale"을 지정하지 않으면, create 메서드는 기본 지역 설정을 사용합니다.
만약 지역 설정을 지정하고 싶다면, 다음과 같이 코드를 작성할 수 있습니다.
#hostingforum.kr
java
Locale locale = Locale.KOREA;
ResourceBundle bundle = ResourceBundle.getBundle("", new PropertiesReader(inputStream), classLoader, locale);
이 코드는 지역 설정을 지정하고, InputStream 객체를 통해 "myResources.properties" 파일을 읽어들입니다.
create 메서드의 파라미터 중 하나인 "name"을 지정하지 않으면, create 메서드는 리소스 파일을 찾지 못하고 Exception을 발생시킵니다.
만약 이름을 지정하고 싶다면, 다음과 같이 코드를 작성할 수 있습니다.
#hostingforum.kr
java
String name = "myResources";
ResourceBundle bundle = ResourceBundle.getBundle(name, new PropertiesReader(inputStream), classLoader, locale);
이 코드는 이름을 지정하고, InputStream 객체를 통해 "myResources.properties" 파일을 읽어들입니다.
create 메서드의 파라미터 중 하나인 "parentBundle"을 지정하지 않으면, create 메서드는 기본 부모 리소스 파일을 사용합니다.
만약 부모 리소스 파일을 지정하고 싶다면, 다음과 같이 코드를 작성할 수 있습니다.
#hostingforum.kr
java
ResourceBundle parentBundle = ResourceBundle.getBundle("parentResources", locale);
ResourceBundle bundle = ResourceBundle.getBundle("", new PropertiesReader(inputStream), classLoader, locale, parentBundle);
이 코드는 부모 리소스 파일을 지정하고, InputStream 객체를 통해 "myResources.properties" 파일을 읽어들입니다.
create 메서드의 파라미터 중 하나인 "baseName"을 지정하지 않으면, create 메서드는 기본 이름을 사용합니다.
만약 이름을 지정하고 싶다면, 다음과 같이 코드를 작성할 수 있습니다.
#hostingforum.kr
java
String baseName = "myResources";
ResourceBundle bundle = ResourceBundle.getBundle(baseName, new PropertiesReader(inputStream), classLoader, locale);
이 코드는 이름을 지정하고, InputStream 객체를 통해 "myResources.properties" 파일을 읽어들입니다.
create 메서드의 파라미터 중 하나인 "parentBundle"을 지정하지 않으면, create 메서드는 기본 부모 리소스 파일을 사용합니다.
만약 부모 리소스 파일을 지정하고 싶다면, 다음과 같이 코드를 작성할 수 있습니다.
#hostingforum.kr
java
ResourceBundle parentBundle = ResourceBundle.getBundle("parentResources", locale);
ResourceBundle bundle = ResourceBundle.getBundle(baseName, new PropertiesReader(inputStream), classLoader, locale, parentBundle);
이 코드는 부모 리소스 파일을 지정하고, InputStream 객체를 통해 "myResources.properties" 파일을 읽어들입니다.
create 메서드의 파라미터 중 하나인 "locale"을 지정하지 않으면, create 메서드는 기본 지역 설정을 사용합니다.
만약 지역 설정을 지정하고 싶다면, 다음과 같이 코드를 작성할 수 있습니다.
#hostingforum.kr
java
Locale locale = Locale.KOREA;
ResourceBundle bundle = ResourceBundle.getBundle(baseName, new PropertiesReader(inputStream), classLoader, locale);
이 코드는 지역 설정을 지정하고, InputStream 객체를 통해 "myResources.properties" 파일을 읽어들입니다.
create 메서드의 파라미터 중 하나인 "parentBundle"을 지정하지 않으면, create 메서드는 기본 부모 리소스 파일을 사용합니다.
만약 부모 리소스 파일을 지정하고 싶다면, 다음과 같이 코드를 작성할 수 있습니다.
#hostingforum.kr
java
ResourceBundle parentBundle = ResourceBundle.getBundle("parentResources", locale);
ResourceBundle bundle = ResourceBundle.getBundle(baseName, new PropertiesReader(inputStream), classLoader, locale, parentBundle);
이 코드는 부모 리소스 파일을 지정하고, InputStream 객체를 통해 "myResources.properties" 파일을 읽어들입니다.
create 메서드의 파라미터 중 하나인 "baseName"을 지정하지 않으면, create 메서드는 기본 이름을 사용합니다.
만약 이름을 지정하고 싶다면, 다음과 같이 코드를 작성할 수 있습니다.
#hostingforum.kr
java
String baseName = "myResources";
ResourceBundle bundle = ResourceBundle.getBundle(baseName, new PropertiesReader(inputStream), classLoader, locale);
이 코드는 이름을 지정하고, InputStream 객체를 통해 "myResources.properties" 파일을 읽어들입니다.
create 메서드의 파라미터 중 하나인 "parentBundle"을 지정하지 않으면, create 메서드는 기본 부모 리소스 파일을 사용합니다.
만약 부모 리소스 파일을 지정하고 싶다면, 다음과 같이 코드를 작성할 수 있습니다.
#hostingforum.kr
java
ResourceBundle parentBundle = ResourceBundle.getBundle("parentResources", locale);
ResourceBundle bundle = ResourceBundle.getBundle(baseName, new PropertiesReader(inputStream), classLoader, locale, parentBundle);
이 코드는 부모 리소스 파일을 지정하고, InputStream 객체를 통해 "myResources.properties" 파일을 읽어들입니다.
create 메서드의 파라미터 중 하나인 "locale"을 지정하지 않으면, create 메서드는 기본 지역 설정을 사용합니다.
만약 지역 설정을 지정하고 싶다면, 다음과 같이 코드를 작성할 수 있습니다.
#hostingforum.kr
java
Locale locale = Locale.KOREA;
ResourceBundle bundle = ResourceBundle.getBundle(baseName, new PropertiesReader(inputStream), classLoader, locale);
이 코드는 지역 설정을 지정하고, InputStream 객체를 통해 "myResources.properties" 파일을 읽어들입니다.
create 메서드의 파라미터 중 하나인 "parentBundle"을 지정하지 않으면, create 메서드는 기본 부모 리소스 파일을 사용합니다.
만약 부모 리소스 파일을 지정하고 싶다면, 다음과 같이 코드를 작성할 수 있습니다.
#hostingforum.kr
java
ResourceBundle parentBundle = ResourceBundle.getBundle("parentResources", locale);
ResourceBundle bundle = ResourceBundle.getBundle(baseName, new PropertiesReader(inputStream), classLoader, locale, parentBundle);
이 코드는 부모 리소스 파일을 지정하고, InputStream 객체를 통해 "myResources.properties" 파일을 읽어들입니다.
create 메서드의 파라미터 중 하나인 "baseName"을 지정하지 않으면, create 메서드는 기본 이름을 사용합니다.
만약 이름을 지정하고 싶다면, 다음과 같이 코드를 작성할 수 있습니다.
#hostingforum.kr
java
String baseName = "myResources";
ResourceBundle bundle = ResourceBundle.getBundle(baseName, new PropertiesReader(inputStream), classLoader, locale);
이 코드는 이름을 지정하고, InputStream 객체를 통해 "myResources.properties" 파일을 읽어들입니다.
create 메서드의 파라
2025-07-28 02:29