---
title: "ResourceBundle和Properties的区别"
author: "layznet"
date: "2010-12-23T12:49:25Z"
tags: []
categories: ["编程语言"]
slug: "resourcebundle-properties"
draft: false
lastmod: "2010-12-23T12:49:25Z"
id: 850099
url: "https://layznet.iteye.com/blog/850099"
---

1、 ResourceBundle只需要指明properties文件名前缀（baseName），不需要.properties后缀。
    Properties需要指明完整的properties文件名。

2、ResourceBundle可以用于资源信息国际化。
   Properties不能国际化资源信息。

3、Properties既可以读取 properties文件信息，也可以往properties文件中写信息；需要显式地构造IO流。
   ResourceBundle只能读取信息，不能写信息，程序员无须关注文件的加载过程。

4、无论系统的默认编码是什么，ResourceBundle和Properties在读取properties文件时统一使用iso8859-1编码。因此，如果在默认编码为GBK的系统中编写了包含中文的properties文件，经由ResourceBundle和Properties读入时，必须转换为GBK格式的编码，否则不能正确识别.

5、资源文件均需要以相对于classpath的根的完整路径提供。
   bin
    |
    |----test
    |   |
    |   ------PropertiesTest.class
    | 
    |----fileopr
    |   |
    |   ------demo.properties
以上示例中，bin目录是所有class文件和资源文件的根目录，那么对于ResourceBundle的参数格式是“fileopr/demo”; 对于Properties的参数格式是“fileopr/demo.properties”;

欢迎留言更正、补充！