private static void writeToFile(Algorithm a, RoundResult[] resultsToReport) { try { PrintWriter pw = new PrintWriter( "resources/results_" + a.getClass().getSimpleName() + "_" + new SimpleDateFormat("yyyyMMdd_kkmm") .format(new Date(System.currentTimeMillis()))); for (RoundResult r : resultsToReport) { pw.println(r.toString()); } pw.flush(); pw.close(); } catch (FileNotFoundException e) { System.err.println("File not found: " + e.getMessage()); for (RoundResult r : resultsToReport) { System.out.println(r.toString()); } } }