public boolean writeFile ( File file , List < String > lines ) { if ( file . exists ( ) ) { file . delete ( ) ; } try { FileWriter out = new FileWriter ( file ) ; for ( String s : lines ) { out . write ( s ) ; out . write ( System . getProperty ( "line.separator" ) ) ; } out . close ( ) ; file . setExecutable ( true ) ; } catch ( IOException ex ) { System . err . println ( this . getAppName ( ) + ": IO exception while writing to file - " + file + " with message: " + ex . getMessage ( ) ) ; return false ; } return true ; }
Writes the given lines to the given file if possible .