📄 propertyoperate.java
字号:
/*
* 创建日期 2005-9-21
*
* TODO 要更改此生成的文件的模板,请转至
* 窗口 - 首选项 - Java - 代码样式 - 代码模板
*/
package cn.itcareers.lxh.exercise.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
/**
* @author 白涛
*
* TODO 要更改此生成的类型注释的模板,请转至 窗口 - 首选项 - Java - 代码样式 - 代码模板
*/
public class PropertyOperate {
/**
* 初始化时读取属性文件
* @return 属性文件的Properties类型的实例化对象
*/
public Properties load() {
File f = new File("person.properties");
Properties pro = new Properties();
if (!f.exists()) {
pro = this.createProperty(f);
} else {
try {
pro.load(new FileInputStream(f));
} catch (FileNotFoundException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
} catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
return pro;
}
/**
* 创建属性文件
* @param f 要操作的文件类
* @return Properties实例化对象
*/
private Properties createProperty(File f) {
Properties pro = new Properties();
pro.put("student", "cn.itcareers.lxh.exercise.person.Student");
pro.put("worker", "cn.itcareers.lxh.exercise.person.Worker");
try {
pro.store(new FileOutputStream(f), "Person INFO");
} catch (FileNotFoundException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
} catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
return pro ;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -