title: Write a file to resources folder in Spring
body: <p>I want to know, how to write a file to a resources folder in a Spring MVC project. 
  I defined the resources path in a <code>web-dispatcher-servlet.xml</code> as<br>
  <code>&lt;mvc:resources mapping="/resources/**" location="/resources/"  /&gt;</code></p>
  
  <p>I read examples about how to read a file from a resources folder. But I want to write a file to a resources folder. I tried</p>
  
  <pre><code>ClassLoader classLoader = getClass().getClassLoader();
      File file = new File(classLoader.getResource("file/test.xml").getFile());
      if (file.createNewFile()) {
          System.out.println("File is created!");
      } else {
          System.out.println("File already exists.");
      }
  </code></pre>
  
  <p>But I get a<br>
   <code>Request processing failed; nested exception is java.lang.NullPointerException</code></p>