在处理文件时,需要先获取文件的路径,这个路径一般取绝对路径,然而,大多时候我们只知道这个文件的相对项目的路径,这时候需要根据文件的相对路径获取绝对路径。
//只能接收相对路径,相对路径字符串最前不可以有/ String filePath = this.getClass().getClassLoader().getResource("templates/excelTemplate/refundApplyExport.xls").getPath(); //能够接受相对路径和绝对路径,相对路径字符串最前一定要有/ String filePath1 = this.getClass().getResource("/templates/excelTemplate/refundApplyExport.xls").getPath();
来源:CSDN
作者:mlsama
链接:https://blog.csdn.net/mlsama/article/details/89713198