spring boot在java中獲取目錄


//獲取跟目錄

String pathPrefix = ResourceUtils.getURL("classpath:").getPath();
File file = new File(pathPrefix);
if(!file.exists()) file = new File("");
System.out.println("file path:"+file.getAbsolutePath());

//獲取文件可以直接如下

//File file = new File("classpath: static/images/test.png");

//如果上傳目錄為/static/images/upload/,則可以如下獲取:
File upload = new File(file.getAbsolutePath(),"static/images/upload/");
if(!upload.exists()) upload.mkdirs();
System.out.println("upload url:"+upload.getAbsolutePath());
//在開發測試模式時,得到的地址為:{項目跟目錄}/target/static/images/upload/

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM