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

推荐订阅源

Martin Fowler
Martin Fowler
T
The Blog of Author Tim Ferriss
J
Java Code Geeks
M
MIT News - Artificial intelligence
F
Fortinet All Blogs
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
B
Blog
Microsoft Azure Blog
Microsoft Azure Blog
I
InfoQ
Microsoft Security Blog
Microsoft Security Blog
N
Netflix TechBlog - Medium
G
Google Developers Blog
L
LangChain Blog
腾讯CDC
大猫的无限游戏
大猫的无限游戏
U
Unit 42
Google DeepMind News
Google DeepMind News
人人都是产品经理
人人都是产品经理
罗磊的独立博客
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
小众软件
小众软件
The GitHub Blog
The GitHub Blog
博客园_首页
GbyAI
GbyAI

博客园 - 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)  评论()    收藏  举报