code: public static boolean writeFile(File directory, File fileName, String text) {
  	try {
  	    File destination = new File(directory, fileName.getPath());
  	    File parent = destination.getParentFile();
  	    if (!parent.exists()) {
  		if (!parent.mkdirs()) {
  		    return false;
  		}
  	    }
  	    RandomAccessFile ra = new RandomAccessFile(destination, "rw");
  	    try {
  		ra.setLength(0);
  		ra.writeBytes(text);
  	    } finally {
  		ra.close();
  	    }
  	    return true;
  	} catch (FileNotFoundException e) {
  	    logger.error(e.getMessage(), e);
  	    return false;
  	} catch (IOException e) {
  	    logger.error(e.getMessage(), e);
  	    return false;
  	}
      }
docs: This method writes the content of a String into a file specified by a
  directory and its fileName.
  
  @param directory
  is the output directory.
  @param fileName
  is the file name of the target file.
  @param text
  is the text to be written into the file.
  @return <code>true</code> is returned in case of success. <code>false</code>
  is returned otherwise.