title: Create a new file everytime, even if the file exists
body: <p>My project requires changing of a particular file contents. I need to create a new everytime the code is executed, irrespective whether the file exists or not. If the file exists, then the original file's content should be deleted and only the new/fresh contents should be present in the file.</p>
  
  <p>Note: The file name and file location will be same in every execution.</p>
  
  <p>Code:</p>
  
  <p>Spring.xml:
  </p>
  
  <pre><code>&lt;bean id=".." class="ImageDataProcess"&gt;
      &lt;constructor-arg ref="x.y.z.filepath.newImageDataFilepath" /&gt;
      &lt;other constructor args&gt;
  &lt;/bean&gt;
  
  &lt;bean id="x.y.z.filepath.newImageDataFilepath"&gt;
       &lt;constructor-arg value="#{tmpDirectoryPath}/image-data.txt" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>ImageDataProcess.java:
  </p>
  
  <pre><code>@RequiredArgsConstructor
  public class ImageDataProcess implements PQR {
    private final String newImageDataTextFilepath;
    //other values coming from spring
        @Override
        public void execute() {
            File f = new File(newImageDataTextFilepath);
            ://logic here
            :
         Forloop(){
            FileUtils.writeStringToFile(f, imageDataFileLine + NEWLINE, true);
          }
      }
  }
  </code></pre>
  
  <p>But this just appends the new contents in the old file.
  As of now, if I run two iterations back to back, the file size becomes just double as it was before, but i want it to be the same, even if data is same.
  Any one knows how can I achieve this??</p>