title: Find the relative path of a FileSystemResource (Spring Boot)
body: <h2>Summary</h2>
  
  <p>In Spring, I can access a resource by specifying a path relative to my <code>src/main/resources/</code> directory. For example, if I ask for <code>/public/index.html</code>, I'll get a <code>FileSystemResource</code> representing <code>/Users/.../src/main/resources/public/index.html</code>. However, I don't see a way to go the opposite direction.</p>
  
  <p>Given a <code>FileSystemResource</code>, is there a way to find its path relative to <code>src/main/resouces/</code>?</p>
  
  <h2>Example</h2>
  
  <p>I'm using <code>PathMatchingResourcePatternResolver</code> to get a list of file resources in my app. The resources I need are located in my app's <code>src/main/resources/public/</code> folder.</p>
  
  <pre class="lang-java prettyprint-override"><code>ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
  for (Resource r : resolver.getResources("/public/**")) {
      // r.getURI().getString() gives me the absolute path.
  }
  </code></pre>
  
  <p>I can easily get the absolute path, but I'd like a way to get the portion starting at <code>/public/</code>, since that's how Spring found it to begin with.</p>