public static void writeData ( final long user , final List < Preference < Long , Long > > recommendations , final String path , final String fileName , final boolean append , final TemporalDataModelIF < Long , Long > model ) { BufferedWriter out = null ; try { File dir = null ; if ( path != null ) { dir = new File ( path ) ; if ( ! dir . isDirectory ( ) ) { if ( ! dir . mkdir ( ) && ( fileName != null ) ) { System . out . println ( "Directory " + path + " could not be created" ) ; return ; } } } if ( ( path != null ) && ( fileName != null ) ) { out = new BufferedWriter ( new OutputStreamWriter ( new FileOutputStream ( path + "/" + fileName , append ) , "UTF-8" ) ) ; } for ( Preference < Long , Long > recItem : recommendations ) { if ( out != null ) { out . write ( user + "\t" + recItem . getItem ( ) + "\t" + recItem . getScore ( ) + "\n" ) ; } if ( model != null ) { model . addPreference ( user , recItem . getItem ( ) , recItem . getScore ( ) ) ; } } if ( out != null ) { out . flush ( ) ; out . close ( ) ; } } catch ( IOException e ) { System . out . println ( e . getMessage ( ) ) ; // logger.error(e.getMessage()); } finally { if ( out != null ) { try { out . close ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } } }
Write recommendations to file .