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 to find something in the “Classpath”. 

Using Resource interface would instantiate an ClassPathResource. 

		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();
		}

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注