zoukankan      html  css  js  c++  java
  • Properties类继承HashTable类,一般用来给程序配置属性文件。

    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);
    }

    }
    }
  • 相关阅读:
    使用 Python 编码和解码 JSON 对象
    搞定github下载加速
    git错误:fatal: Could not read from remote repository.解决
    webstorm安装配置
    node.js下载安装
    IDEA安装小配置
    JAVA软件安装
    关于升级一般软件的一些想法
    linux 的 逻辑卷管理
    记一次内核升级。
  • 原文地址:https://www.cnblogs.com/newcityboy/p/11258934.html
Copyright © 2011-2022 走看看