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