title: Writing to a File in Java
body: <p>I'm really new to Java, and I can't write to a file for some reason, my code looks like this:</p>
  
  <pre><code>FileWriter fstream;
      try {
          fstream = new FileWriter(fileLocation);
          BufferedWriter out = new BufferedWriter(fstream);
          log.info("test was supposed to be written to the file");
          out.write("test");
  
          out.flush();
          out.close();
  
      } catch (IOException e) {
          log.error("File not created ", e);
      }
  </code></pre>
  
  <p>When I go to the fileLocation, I see my file, but it's empty. My log does say "test was supposed to be written to the file"</p>
  
  <p>What could I be doing wrong here? </p>
  
  <p>Thanks!</p>
  
  <p>UPDATE: My FileLocation variable is a string:</p>
  
  <pre><code>private String fileLocation="/Users/s/out.txt";
  </code></pre>
  
  <p>I'm using a Mac</p>