---
# System prepended metadata

title: ResourceBundle的用法
tags: [ocpjp]

---

# ResourceBundle的用法
-[參考網站](https://openhome.cc/Gossip/Encoding/ResourceBundle.html)

```java=
Given the Greetings.properties file, containing:

HELLO_MSG = Hello, everyone!
GOODBYE_MSG = Goodbye everyone!

And given:

import java.util.Enumeration;
import java.util.Locale;
import java.util.ResourceBundle;

public class ResourceApp {

    public void loadResourceBundle() {
        ResourceBundle resource = ResourceBundle.getBundle(“Greetings”, Locale.US);
        System.out.println(resource.getObject(1));
    }

    public static void main(String[] args) {
        new ResourcesApp().loadResourceBundle();
    }
}
```

What is the result?
**A. Compilation fails.**
B. GOODBY_MSG
C. Hello, everyone!
D. Goodbye everyone!
E. HELLO_MSG
- [x] **Answer: A**

:::info
getObject(String key)
要輸入properties的key , 才可以得到該值
:::

###### tags: `ocpjp`