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

📄 proputils.java

📁 聊天工具
💻 JAVA
字号:
package utils;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

import javax.swing.JOptionPane;

/**
 *  配置文件实用类
 * @author 洪景泉
 *
 */
 
public class PropUtils {
	public static Properties p;

	/**
	 * 在程序类加裁之前运行
	 */
	static {
		p = new Properties();
		try {
			FileInputStream fis = new FileInputStream("./configure/config.ini");
			p.load(fis);
		} catch (IOException e) {
			JOptionPane.showMessageDialog(null,
					"加载配置文件出错!\n请与技术员联系!", "出错啦",
					JOptionPane.ERROR_MESSAGE);
			System.exit(1);
			e.printStackTrace();
		}
	}

	/**
	 * 根据传入的 key 获取配置文件内的值。
	 * 
	 */
	public static String read(String key) {

		return p.getProperty(key);
	}

	/**
	 * 据传入的 key value 写入配置文件
	 * 
	 */
	public static void write(String key, String value) {
		p.setProperty(key, value);// 到此为止,新的key value 仅存在内存
		try {
			FileOutputStream fos = new FileOutputStream("./configure/config.ini");
			p.store(fos, null);
		} catch (IOException e) {
		
			e.printStackTrace();
		}

	}
	
	public static void main(String[] args) {
//		PropUtils.write("url", urlText.getText());
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -