title: springframework.core.io.Resource always throw java.io.FileNotFoundException
body: <p>I am a beginner for Spring, and I am learning Resource.</p>
  
  <pre><code>package com.smart.beanfactory;
  
  import org.springframework.core.io.ClassPathResource;
  import org.springframework.core.io.Resource;
  
  public class BeanLifeCycle {
      private static void LifeCycleInBeanFactory() {
          Resource res = new ClassPathResource("classpath:com/smart/beanfactory/beans.xml");
          try {
              System.out.println(res.getURL());
          } catch (Exception e) {
              System.out.println(e.fillInStackTrace());
          }
      }
  
      public static void main(String[] args) {
          LifeCycleInBeanFactory();
      }
  }
  </code></pre>
  
  <p>I write the above simple code just to use the classpath to load the .xml file. </p>
  
  <p>Below is the hierarchy of my project:
  <a href="https://i.stack.imgur.com/RL1O5.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RL1O5.jpg" alt="enter image description here"></a></p>
  
  <p>Then I tried the absolute file path in <code>Resource res = new ClassPathResource("file:/Users/haoxu/Documents/Code/Java/anotherchapter4/src/main/resources/com.smart/beanfactory/beans.xml");</code>
  But that also cannot work.
  It just told me "java.io.FileNotFoundException: class path resource [Users/haoxu/Documents/Code/Java/anotherchapter4/src/main/resources/com.smart/beanfactory/beans.xml] cannot be resolved to URL because it does not exist
  "</p>
  
  <p>-----------update--------</p>
  
  <p>I modified my code to:</p>
  
  <pre><code>package com.smart.beanfactory;
  
  import org.springframework.core.io.ClassPathResource;
  import org.springframework.core.io.Resource;
  
  import java.io.File;
  
  public class BeanLifeCycle {
      private static void LifeCycleInBeanFactory() {
          Resource res = new ClassPathResource("/com/smart/beanfactory/beans.xml");
          try {
              System.out.println(res.getURL());
          } catch (Exception e) {
              System.out.println(e.fillInStackTrace());
          }
      }
  
      public static void main(String[] args) {
          LifeCycleInBeanFactory();
      }
  }
  </code></pre>
  
  <p>But I still get "java.io.FileNotFoundException: class path resource [com/smart/beanfactory/beans.xml] cannot be resolved to URL because it does not exist"</p>