import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.Set;
import java.util.Map.Entry;
public class ParseFile {
public static void main(String[] args) {
//获取属性文件二进制流
InputStream is = ParseFile.class.getResourceAsStream("config.properties");
Properties properties = new Properties();
try {
//装载属性文件
properties.load(is);
} catch(IOException e) {
e.printStackTrace();
}
//用制定的属性名获取属性值
String path = properties.getProperty("path");
System.out.println(path);
//遍历所有属性
Set<Entry<Object, Object>> set = properties.entrySet();
for (Entry<Object, Object> entry : set) {
System.out.println(entry.getKey());
System.out.println(entry.getValue());
}
}
}
import java.io.InputStream;
import java.util.Properties;
import java.util.Set;
import java.util.Map.Entry;
public class ParseFile {
public static void main(String[] args) {
//获取属性文件二进制流
InputStream is = ParseFile.class.getResourceAsStream("config.properties");
Properties properties = new Properties();
try {
//装载属性文件
properties.load(is);
} catch(IOException e) {
e.printStackTrace();
}
//用制定的属性名获取属性值
String path = properties.getProperty("path");
System.out.println(path);
//遍历所有属性
Set<Entry<Object, Object>> set = properties.entrySet();
for (Entry<Object, Object> entry : set) {
System.out.println(entry.getKey());
System.out.println(entry.getValue());
}
}
}