Java代碼
package com
import java
import java
import java
import java
import java
import java
import java
import java
public class TestMain {
// 根據key讀取value
public static String readValue(String filePath
Properties props = new Properties();
try {
InputStream in = new BufferedInputStream(new FileInputStream(
filePath));
props
String value = props
System
return value;
} catch (Exception e) {
e
return null;
}
}
// 讀取properties的全部信息
public static void readProperties(String filePath) {
Properties props = new Properties();
try {
InputStream in = new BufferedInputStream(new FileInputStream(
filePath));
props
Enumeration en = props
while (en
String key = (String) en
String Property = props
System
}
} catch (Exception e) {
e
}
}
// 寫入properties信息
public static void writeProperties(String filePath
String parameterValue) {
Properties prop = new Properties();
try {
InputStream fis = new FileInputStream(filePath);
// 從輸入流中讀取屬性列表(鍵和元素對)
prop
// 調用 Hashtable 的方法 put
// 強制要求為屬性的鍵和值使用字符串
OutputStream fos = new FileOutputStream(filePath);
prop
// 以適合使用 load 方法加載到 Properties 表中的格式
// 將此 Properties 表中的屬性列表(鍵和元素對)寫入輸出流
prop
} catch (IOException e) {
System
+ parameterName +
}
}
public static void main(String[] args) {
readValue(
writeProperties(
readProperties(
System
}
}
From:http://tw.wingwit.com/Article/program/Java/hx/201311/25927.html