Springboot: controller access files through Resource Interface
Access files through classpath.
Springboot will scan /META-INF/resources/; /resources/; /static/ and/public/ folders when you tell it find something in the “Classpath”.
Using Resource interface to instantiate an ClassPathResource.
1 2 3 4 5 6 7 8 9 |
Resource resource =new ClassPathResource("RelativePathOfYourFile, root of /META-INF/resources/; /resources/; /static/ or /public/"); try { String path =resource.getFile().getAbsolutePath(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } |