获取src资源文件编译后的路径(即classes路径)

//获取src资源文件编译后的路径(即classes路径)

URL resource = this.getClass().getClassLoader().getResource("template/paramTemplate.xlsx");
if (resource == null) {
    throw new CustomException(600, "模板文件不存在");
}
String fileNamePath = resource.getPath();
ExcelUtil.downloadFile(response, new File(fileNamePath));

//处理路径中文乱码

File directory = new File(java.net.URLDecoder.decode(url.getPath(), "utf-8"));
posted @ 2022-02-04 19:32  码农公子的幸福生活  阅读(119)  评论(0)    收藏  举报