码迷,mamicode.com
首页 > 其他好文 > 详细

Properties类继承HashTable类,一般用来给程序配置属性文件。

时间:2019-07-28 16:01:14      阅读:219      评论:0      收藏:0      [点我收藏+]

标签:table   demo   继承   val   color   nal   span   属性   ===   

package com.itcast.demo04.Prop;

import jdk.internal.util.xml.impl.ReaderUTF8;
import sun.nio.cs.UTF_32;
import sun.nio.cs.ext.GBK;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;
import java.util.Set;

/**
* @author newcityman
* @date 2019/7/28 - 12:50
*/
public class Demo01Properties {
public static void main(String[] args) throws IOException {
// show01();
// show02();
show03();

}

private static void show03() throws IOException {
Properties prop = new Properties();
prop.load(new FileReader("day18_IOAndProperties\\prop.txt"));
Set<String> key = prop.stringPropertyNames();
for (String s : key) {
String value = prop.getProperty(s);
System.out.println(s+"==>"+value);
}
}

private static void show02() throws IOException {
Properties prop = new Properties();
prop.setProperty("张曼玉","16");
prop.setProperty("张学友","20");
prop.setProperty("刘德华","18");

FileWriter fw = new FileWriter("day18_IOAndProperties\\prop.txt");

prop.store(fw, "data");
}


private static void show01() {
Properties prop = new Properties();
prop.setProperty("zmy","12");
prop.setProperty("zyy","20");
prop.setProperty("lm","15");
prop.setProperty("zgh","16");
Set<String> strings = prop.stringPropertyNames();
for (String key : strings) {
String value = prop.getProperty(key);
System.out.println(key+"====>"+value);
}

}
}

Properties类继承HashTable类,一般用来给程序配置属性文件。

标签:table   demo   继承   val   color   nal   span   属性   ===   

原文地址:https://www.cnblogs.com/newcityboy/p/11258934.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!