public static void writeStringToFile(File file,String s,String charset,boolean append) throws IOException {
  if (s == null)   return;
  try (OutputStream out=new FileOutputStream(file,append)){
    out.write(s.getBytes(charset));
  }
 }

public static void writeStringToFile ( File file , String s , String charset , boolean append ) throws IOException { if ( s == null ) return ; try ( OutputStream out = new FileOutputStream ( file , append ) ) { out . write ( s . getBytes ( charset ) ) ; } }
writes string to file .
