Java读取属性文件

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Properties;
import java.util.Set;

public class ReadFile {

public void ReadPropertiesFile(String propertiesFile) {
Properties props = new Properties();
try {
InputStream inputStream = new FileInputStream(propertiesFile);
props.load(inputStream);
Set set = props.keySet();
Iterator ite = set.iterator();
while (ite.hasNext()) {
String key = (String) ite.next();
String value = props.getProperty(key);
System.out.println("key==========" + key);
System.out.println("value==========" + value);
}
}
catch (IOException e) {
e.printStackTrace();
}
}

public static void main(String[] args) {
// new ReadFile().ReadPropertiesFile("e:\\test.properties");
}

你可能感兴趣的:(java)