后端读取本地文件:

  • 使用org.springframework.core.io.ClassPathResource 读取相对classes文件夹下的文件
Resource r1 = new ClassPathResource("类路径/conf/a.txt");

InputStream i1 = r1.getInputStream();
  • org.springframework.core.io.FileSystemResource
Resource r2= new FileSystemResource("全路径");
InputStream i2 = r2.getInputStream();
  • Resource接口定义多个方法;

                        spring开发总结

 

注意Resource实现文件加载时,默认使用操作系统的编码格式,一定程度上需要转换乱码问题

                            spring开发总结

 

  • FileCopyUtils工具类常用方法

                 spring开发总结

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

相关文章:

  • 2021-05-17
  • 2021-08-04
  • 2022-02-05
  • 2021-12-02
  • 2021-11-28
  • 2021-11-28
  • 2021-12-24
猜你喜欢
  • 2021-10-23
  • 2021-09-18
  • 2022-02-22
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案