示例如下:
假设有一个test.properties如下:
#表示注释
test1=This is Java properties#默认的properties是不认中文的,需要编码
test2=Welcome to Java World Java读取
Java有好几种方法来读取properties文件
public class Test {
public static void main(String args[]) {
try {
String name = "test.properties";InputStream in = new BufferedInputStream(new FileInputStream(name));
Properties p = new Properties(); p.load(in);
System.out.println("test1的值=="+p.getProperty("test1"));System.out.println("test2的值=="+p.getProperty("test2")); }
catch (Exception err) {
err.printStackTrace();
}}
test2的值==Welcome to Java World
参照:http://wenku.baidu.com/view/fa55206858fafab069dc0254.html?pn=151