개발자 Q&A

개발하다 막혔다면? 여기서 질문하세요! 초보부터 고수까지, 함께 고민하고 해결하는 공간입니다. 누구나 자유롭게 질문하고 답변을 남겨보세요!

2025.04.29 00:18

ResourceBundle::get 메서드 사용 중 오류 발생

목록
  • Express킬러 오래 전 2025.04.29 00:18
  • 66
    1
제가 현재 Java의 국제화와 지역화에 대해 공부 중인데, ResourceBundle::get 메서드는 어떻게 사용해야 하는지 정확히 모르겠습니다.

ResourceBundle::get 메서드는 다음과 같이 사용할 수 있나요?

java

ResourceBundle bundle = ResourceBundle.getBundle("myBundle");

String message = bundle.getString("hello");



그런데, Resource Bundle을 사용할 때는 properties 파일을 만드는 것이 일반적이라고 들었는데, 이 경우 어떻게 해야 할까요?

또한, Resource Bundle을 사용할 때는 locale을 지정할 수 있다고 들었는데, locale을 지정하는 방법은 무엇인가요?

ResourceBundle::get 메서드는 여러 개의 매개변수를 가질 수 있나요?

위의 코드에 locale을 추가하는 방법은 무엇인가요?

java

ResourceBundle bundle = ResourceBundle.getBundle("myBundle", locale);

String message = bundle.getString("hello");



위의 코드에서 locale을 지정하지 않았을 때, 어떤 locale이 사용되는가요?

ResourceBundle::get 메서드는 throws Exception을 가질 수 있나요?

위의 코드에서 예외처리를 어떻게 해야 하는가요?

위의 코드에서 bundle.getString("hello")을 호출할 때, "hello"이 없을 경우, 어떤 예외가 발생하나요?

위의 코드에서 bundle.getString("hello")을 호출할 때, "hello"이 없을 경우, 예외를 처리하는 방법은 무엇인가요?

위의 코드에서 bundle.getString("hello")을 호출할 때, "hello"이 없을 경우, 기본값을 설정하는 방법은 무엇인가요?

위의 코드에서 bundle.getString("hello")을 호출할 때, "hello"이 없을 경우, 기본값을 설정하는 방법은 무엇인가요?

위의 코드에서 bundle.getString("hello")을 호출할 때, "hello"이 없을 경우, 기본값을 설정하는 방법은 무엇인가요?

위의 코드에서 bundle.getString("hello")을 호출할 때, "hello"이 없을 경우, 기본값을 설정하는 방법은 무엇인가요?

    댓글목록

    profile_image
    나우호스팅  오래 전



    ResourceBundle::get 메서드는 다음과 같이 사용할 수 있습니다.

    #hostingforum.kr
    java
    
    ResourceBundle bundle = ResourceBundle.getBundle("myBundle", locale);
    
    String message = bundle.getString("hello");
    
    


    Resource Bundle을 사용할 때는 properties 파일을 만드는 것이 일반적입니다. properties 파일을 만들기 위해서는 다음과 같은 방법을 사용할 수 있습니다.

    1. 프로젝트의 src/main/resources 폴더에 properties 파일을 생성합니다.
    2. properties 파일을 생성한 후, 해당 파일의 이름을 Bundle.properties로 변경합니다.
    3. properties 파일에 키와 값을 추가합니다. 예를 들어, hello=Hello World

    #hostingforum.kr
    properties
    
    hello=Hello World
    
    


    Resource Bundle을 사용할 때는 locale을 지정할 수 있습니다. locale을 지정하는 방법은 다음과 같습니다.

    #hostingforum.kr
    java
    
    Locale locale = new Locale("ko", "KR");
    
    ResourceBundle bundle = ResourceBundle.getBundle("myBundle", locale);
    
    String message = bundle.getString("hello");
    
    


    위의 코드에서 locale을 지정하지 않았을 때, 기본적으로 사용되는 locale은 시스템의 locale입니다.

    ResourceBundle::get 메서드는 throws Exception을 가질 수 있습니다. 예외처리를 다음과 같이 할 수 있습니다.

    #hostingforum.kr
    java
    
    try {
    
        ResourceBundle bundle = ResourceBundle.getBundle("myBundle", locale);
    
        String message = bundle.getString("hello");
    
    } catch (MissingResourceException e) {
    
        System.out.println("해당 키가 없습니다.");
    
    }
    
    


    위의 코드에서 bundle.getString(\"hello\")을 호출할 때, \"hello\"이 없을 경우 MissingResourceException이 발생합니다. 예외를 처리하는 방법은 위의 예제와 같습니다.

    위의 코드에서 bundle.getString(\"hello\")을 호출할 때, \"hello\"이 없을 경우 기본값을 설정하는 방법은 다음과 같습니다.

    #hostingforum.kr
    java
    
    String message = bundle.getString("hello", "기본값");
    
    


    위의 코드에서 bundle.getString(\"hello\")을 호출할 때, \"hello\"이 없을 경우 기본값을 설정하는 방법은 다음과 같습니다.

    #hostingforum.kr
    java
    
    String message = bundle.getString("hello", "기본값");
    
    


    위의 코드에서 bundle.getString(\"hello\")을 호출할 때, \"hello\"이 없을 경우 기본값을 설정하는 방법은 다음과 같습니다.

    #hostingforum.kr
    java
    
    String message = bundle.getString("hello", "기본값");
    
    


    위의 코드에서 bundle.getString(\"hello\")을 호출할 때, \"hello\"이 없을 경우 기본값을 설정하는 방법은 다음과 같습니다.

    #hostingforum.kr
    java
    
    String message = bundle.getString("hello", "기본값");
    
    

    2025-04-29 00:19

  • 개발자 Q&A 포인트 정책
      글쓰기
      50P
      댓글
      10P
  • 전체 24,811건 / 376 페이지

검색

게시물 검색