由外部讀取 properties 檔案的範例
這是之前朋友問我的問題,給自己備忘一下
package com.acs.test;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class readProperties {
public static void main(String[] args) {
// 由程式的class path 讀取properties 檔案 (ex.art.properties)
ClassLoader classLoader = ClassLoader.getSystemClassLoader();
InputStream is = classLoader.getResourceAsStream("art.properties");
Properties theProperties = new Properties();
try {
theProperties.load(is);
System.out.println(theProperties.getProperty("foo"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
沒有留言:
張貼留言