读写properties文件
Java读写Properties文件是一个比较常见的需求,一般的做法是将properties文件读到Properties类对象中,通过Properteis对象来操作。下面是一段实例代码:
/**
* Read Properties file with ASCII codes only
*/
public static Properties getProperties(String fileName, String path){
Properties props = new Properties();
InputStream in = null;
try {
in = new FileInputStream(path + fileName);
} catch (FileNotFoundException e1) {
System.out.println("Can't find c3p0.properties");
}
try {
props.load(in);
in.close();
} catch (IOException e) {
System.out.println("Can't load c3p0.properties");
}
return props;
}
上面的代码是用于读取仅包含ASCII码的properties文件,特点是只用了FileInputStream,而没有像往常一样在外面套个FileReader。下面的代码用于写ASCII编码的properties文件:
/**
*
*/
private void setPa