public static File writeFile ( String filename , String content ) { PrintWriter pw = null ; try { pw = new PrintWriter ( filename , FILE_ENCODING ) ; pw . write ( content ) ; pw . flush ( ) ; } catch ( FileNotFoundException e ) { throw new IllegalArgumentException ( "Unable to write to: " + filename , e ) ; } catch ( UnsupportedEncodingException e ) { throw new RuntimeException ( e ) ; } finally { if ( pw != null ) { pw . close ( ) ; } } return new File ( filename ) ; }
Writes content to file in UTF - 8 encoding .