美文网首页
2020-08-11Properties处理属性文件

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

作者: DM小强 | 来源:发表于2020-08-11 16:10 被阅读0次

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

        }
    }
}

相关文章

网友评论

      本文标题:2020-08-11Properties处理属性文件

      本文链接:https://www.haomeiwen.com/subject/updydktx.html