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

📄 operateproperties.java

📁 该多线程下载工具功能强大
💻 JAVA
字号:
package coursedesign;

import java.io.*;
import java.util.*;

public class OperateProperties {

	private static String filePath = "E:\\";

	private FileOutputStream fos = null;

	// 读取文件里相应的值
	public String readValue(String fileName, String key) {
		Properties props = new Properties();
		try {
			File file = new File(filePath + fileName);
			FileInputStream fis = new FileInputStream(file);
			InputStream ips = new BufferedInputStream(fis);
			props.load(ips);
			String value = props.getProperty(key);

			fis.close();
			ips.close();
			return value;
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			return null;
		} catch (IOException e) {
			e.printStackTrace();
			return null;
		}
	}

	// 写入文件里相应的值
	public void writeProperties(String fileName, String paraKey,
			String paraValue) {

		File file = new File(filePath + fileName);
		try {
			if (!file.exists()) {
				file.createNewFile();

			}
		} catch (IOException ex) {
			ex.printStackTrace();
		}

		Properties props = new Properties();
		try {
			FileInputStream fis = new FileInputStream(file);
			props.load(fis);
			props.setProperty(paraKey, paraValue);
			props.store(new FileOutputStream(file), "header");

			fis.close();

		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}

⌨️ 快捷键说明

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