Java工程中读取resources目录下properties文件

public class JdbcConfig {
    public static void main(String[] args) {
        JdbcConfig jdbcConfig = new JdbcConfig();
        Properties p = jdbcConfig.getJdbcConfig();

    }
    public Properties getJdbcConfig() {
        InputStream in = this.getClass().getResourceAsStream("/db.properties");
        Properties props = new Properties();
        try{
            InputStreamReader inputStreamReader = new InputStreamReader(in, "UTF-8");
            props.load(inputStreamReader);
        }catch (IOException e){
            e.printStackTrace();
        }



        return props;
    }

 

 

你可能感兴趣的:(java)