【异常总结】java获取properties文件失败

InputStream in = this.getClass().getResourceAsStream("/properties/vehicle-base64.properties");
Properties properties = new Properties();
try {
    properties.load(in);
} catch (IOException e) {
    throw BaseException.of(ViasErrorCode.PROPERTIES_LOAD_ERROR.of());
}

这段代码之前用过,能正常读取properties文件,自从将要读取的文件重新生成之后就抛异常了,打断点发现 in 值为 null.
而打开properties文件发现内容好像也没什么问题,除了因为每行字符太多idea将它自动换行了。通过排查,发现问题就出在换行!(真坑)
取消掉idea自动换行后这个问题就解决了。

猜你喜欢

转载自blog.csdn.net/qq_21084687/article/details/83586459