惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
博客园 - 三生石上(FineUI控件)
D
DataBreaches.Net
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
GbyAI
GbyAI
P
Proofpoint News Feed
Microsoft Security Blog
Microsoft Security Blog
月光博客
月光博客
I
InfoQ
V
Visual Studio Blog
罗磊的独立博客
Engineering at Meta
Engineering at Meta
Vercel News
Vercel News
Jina AI
Jina AI
L
LangChain Blog
Apple Machine Learning Research
Apple Machine Learning Research
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
B
Blog
The Cloudflare Blog
小众软件
小众软件
雷峰网
雷峰网
V
V2EX
人人都是产品经理
人人都是产品经理
Stack Overflow Blog
Stack Overflow Blog

博客园 - Xsi64

STS或eclipse安装SVN插件 Html解析类的新选择CsQuery Tomcat编码问题 在64位平台上的Lucene,应该使用MMapDirectory[转] Cache Lucene IndexReader with Apache Commons Pool apache commons pool deb软件包安装和卸载 maven GroupId 和ArtifactId通常填什么 mongodb first mongodb mongod 启动参数 Could not resolve archetype org.apache.maven.archetypes:maven-archetype-quickstart 在CentOS上安装tomcat CentOS上安装 jdk centOS上安装redis Linux CentOS修改网卡IP/网关设置 vim使用大全 [Redis] redis-cli 命令总结 CentOS装机必备-基本设置以及缺失文件 maven scope含义的说明
Java properties文件用法
Xsi64 · 2014-06-06 · via 博客园 - Xsi64
package com.suyang.properties;

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

public class TestProperties {

	private final String PATH = "test.properties";
	private static Properties props = new Properties();

	static {
		try {
			props.load(new FileInputStream("test.properties"));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public String getProperty(String name) {
		return props.getProperty(name);
	}

	public void setProperty(String name, String value) {
		props.setProperty(name, value);
	}
	
	public void save(){
		OutputStream fos = null;
		try {
			fos = new FileOutputStream(PATH);
			props.store(fos, "");
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}  finally{
			if(fos != null){
				try {
					fos.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}
}

posted @ 2014-06-06 13:35  Xsi64  阅读(279)  评论()    收藏  举报