你还在为开发springBoot项目时,获取文件存放地址而发愁,下面三种方式能够帮助你

第一种:直接访问绝对路径:(不灵活,需要在固定盘符,每次迁移项目需要注意)

File file = new File("D:\\hjf\\simsunttc\\simsun.ttc");

 

 

第二种:直接放入resource 目录下(缺点:打成jar 包时,访问不到文件地址)

File file = new File("项目名/src/main/resources/simsun.ttc");

 

 

第三种:直接放入resource 目录下(最优打成jar 依然可以访问)

注意:验证后这种方式打成jar后依然不行

ClassPathResource classPathResource = new ClassPathResource("simsun.ttc");
File file = new File(classPathResource.getURL().getPath());

相关文章:

  • 2022-12-23
  • 2022-01-29
  • 2022-12-23
  • 2022-01-01
  • 2021-09-24
  • 2022-12-23
  • 2021-11-20
  • 2022-12-23
猜你喜欢
  • 2022-02-07
  • 2021-10-12
  • 2021-12-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案