void (int i, boolean doSync) { try { final File tempFile = FileUtil.createTempFile("test", "test" + i); try (FileWriter writer = new FileWriter(tempFile)) { for (int j = 0; j < 15; j++) { writer.write("test" + j); writer.flush(); } } try (FileReader reader = new FileReader(tempFile)) { //noinspection StatementWithEmptyBody while (reader.read() >= 0) { } } if (doSync) { try (FileOutputStream stream = new FileOutputStream(tempFile)) { stream.getFD().sync(); } } if (!tempFile.delete()) { throw new IOException("Unable to delete: " + tempFile); } } catch (IOException e) { throw new RuntimeException(e); } }