A5下载文章资讯

分类分类

Properties文件的设置

2015-07-08 11:43作者:zhao

在java中经常需要输入一些配置文件方便程序的管理。最常使用的一个方式就是设置Properties文件。

package com.app.property;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.util.Properties;

public class FileProperty {

public static void main(String[] args) throws Exception {

//设置二级配置文件(一级配置文件的默认值)

Properties defaultProperty = new Properties();

defaultProperty.put("name", "wx");

defaultProperty.put("age", 16);

defaultProperty.put("gender", "boy");

//设置一级配置文件

Properties p2 = new Properties(defaultProperty);

p2.put("size", "30");

//存储配置文件

FileOutputStream out = new FileOutputStream(new File(

"src/out.properties"));

p2.store(out, "programming property");

//加载配置文件

FileInputStream ins = new FileInputStream(

new File("src/out.properties"));

p2.load(ins);

System.out.println(p2.getProperty("name"));

}

}

展开全部

相关

说两句网友评论
    我要跟贴
    取消