Maven项目相对路径读取resources下文件的路径问题

//获取文件相对路径,path是自己定义的路径参数
InputStream inputStream =getClass().getClassLoader().getResourceAsStream(path);

prop.load(inputStream);

在这里插入图片描述

这个方法会自动加载target/classes路径下面的文件。请看我的demo

public static void main(String[] args) {
    PropertiesUtil propertiesUtil = new PropertiesUtil();
    propertiesUtil.init("config.properties");
}

猜你喜欢

转载自blog.csdn.net/qq_34362409/article/details/100168901
今日推荐