1、读文件中的某项值:
//根据文件路径名加载对应的文件
InputStream inputStream = new FileInputStream(this.componentFilePath);
//设定Properties
Properties p = new Properties();
//将InputStream加载到Properties中
p.load(inputStream);
//获取特定项的值
String componentID = p.getProperty(APP_COMPONENTID);
//返回特定的值
return componentID;
2、写文件
//创建File对象
File ft = new File(this.componentFilePathTemp);
//createNewFile
ft.createNewFile();
//定义FileWriter
FileWriter fw = null;
//定义BufferedWriter
BufferedWriter bw = null;
try {
fw = new FileWriter(ft);
bw = new BufferedWriter(fw);
//写数据到Buffer中
bw.write(APP_COMPONENTID + "=" + this.componentID);
//清空Buffer
bw.flush();
}
catch(IOException e){
e.printStackTrace();
}