springboot項目上傳或獲取resources目錄下文件
獲取:
File file = ResourceUtils.getFile(ResourceUtils.CLASSPATH_URL_PREFIX+“img/qrcode.png”);
上傳:
首先要獲取到resources文件夾下的img目錄的位置
File path = new File(ResourceUtils.getURL(“classpath:”).getPath());
//如果上傳目錄爲/img/,則可以如下獲取:
File upload = new File(path.getAbsolutePath(),“img/”);
upload: url:D:\IdeaProjects\qr-code-tool\target\classes\img
ok,問題解決