java解析配置文件

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

public class Javatest94 {
    /**
     * 解析jdbc配置文件
     */
    public static void main(String[] args) {
        Properties properties = new Properties();
        try {
            //加载配置文件
            properties.load(Javatest94.class.getClassLoader().getResourceAsStream("jdbc.properties"));
        } catch (IOException e) {
            e.printStackTrace();
        }
        String url = properties.getProperty("jdbc.url");
        String username = properties.getProperty("jdbc.username");
        String password = properties.getProperty("jdbc.password");
        System.out.println("url = " + url);
        System.out.println("username = " + username);
        System.out.println("password = " + password);
    }
}

 

posted @ 2022-04-23 16:39  翼小白  阅读(193)  评论(0)    收藏  举报