How to access a resource file in src/main/resources/ folder in Spring Boot

后端 未结 3 975
南方客
南方客 2021-01-03 00:25

I\'m trying to access xsd in src/main/resources/XYZ/view folder where XYZ/view folder are created by me and folder has abc.xsd which I need for xml validation.

When

3条回答
  •  南笙
    南笙 (楼主)
    2021-01-03 00:45

    You may use bellow like ..

    1. My resource file location is like bellow

    I have use bellow like in spring boot

    @Autowired
    private ResourceLoader resourceLoader;
    
      try {     
    
       final Resource resource = resourceLoader.getResource("classpath:files/timezoneJson.json");
             Reader reader = new InputStreamReader(resource.getInputStream());
             String filedata =  FileCopyUtils.copyToString(reader);
        } catch (Exception e) {     
            e.printStackTrace();
        }
    

提交回复
热议问题