2020-08-11Properties处理属性文件

2020-08-11  本文已影响0人  DM小强

Properties处理属性文件

package com.at.test;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

/**
 * @author JessieWu
 * @create 2020-08-11  16:56
 */
public class PropertiesTest {
    public static void main(String[] args) throws Exception {
        FileInputStream fileInputStream = null;
        try {
            Properties properties = new Properties();
            fileInputStream = new FileInputStream("jdbc.properties");
            properties.load(fileInputStream);//加载文件
            String name = properties.getProperty("name");
            String password = properties.getProperty("password");
            System.out.println("name=" + name + " password=" + password);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if(fileInputStream != null){
                fileInputStream.close();
            }

        }
    }
}

上一篇下一篇

猜你喜欢

热点阅读