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

推荐订阅源

WordPress大学
WordPress大学
J
Java Code Geeks
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
腾讯CDC
IT之家
IT之家
罗磊的独立博客
酷 壳 – CoolShell
酷 壳 – CoolShell
U
Unit 42
爱范儿
爱范儿
博客园 - 聂微东
F
Fortinet All Blogs
V
Visual Studio Blog
Blog — PlanetScale
Blog — PlanetScale
G
Google Developers Blog
aimingoo的专栏
aimingoo的专栏
L
LangChain Blog
雷峰网
雷峰网
B
Blog RSS Feed
宝玉的分享
宝玉的分享
T
Tailwind CSS Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Engineering at Meta
Engineering at Meta
H
Hackread – Cybersecurity News, Data Breaches, AI and More

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