⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 propertyoperate.java

📁 学校的学生和工人管理系统 可以完成增删改查的功能
💻 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 + -