获取当前运行绝对路径

通过getclass()的方式去获取可能会出现空指针异常
UploadUtil.class.getClass().getResource("/").getPath()

解决方案:通过类加载器ClassLoader去获取

UploadUtil.class.getClassLoader().getResource("/").getPath();

 

posted @ 2020-03-31 14:18  Dorom  阅读(189)  评论(0)    收藏  举报