code: public void writeToFile(String filePath, String fileData, boolean append)
          throws IOException {
  
          // synchronized on an interned string makes has all the
          // makings for exclusive write access as far as this
          // process is concerned.
          String path = (String) Utils.intern(filePath);
          synchronized (path) {
              File file = null;
              FileWriter fileWriter = null;
              try {
                  file = new File(path);
                  boolean exists = file.exists();
                  if (!exists) {
                      exists = file.getParentFile().mkdirs();
                      exists = file.createNewFile();
                  }
                  if (exists) {
                      fileWriter = new FileWriter(file, append);
                      fileWriter.write(fileData);
                      fileWriter.flush();
                  } else {
                      String msg =
                          "File could not be created. (" + filePath + ")";
                      mLog.error(msg);
                      throw new IOException(msg);
                  }
              } catch (IOException e) {
                  mLog.error("Error writing: " + filePath);
                  mLog.error(e);
                  throw e;
              } finally {
                  if (fileWriter != null) {
                      fileWriter.close();
                  }
              }
          }
      }
docs: Write the contents of the given file data to the file at the given path.
  If the append flag is <code>true</code>, the file data will be appended
  to the end of the file if it already exists. Note that this will attempt
  to create any and all parent directories if the path does not exist.
  
  @param filePath The path to the file to write to
  @param fileData The data to write to the given file
  @param append Whether to append the file data or replace existing data
  
  @throws IOException if an error occurs writing the data