@Test public void updateFileHandleTest() throws IOException { File dir = new File(BASE_PKG + SLASH + TEST_FILE); dir.mkdirs(); File createFile = new File(dir + TEST_FILE); createFile.createNewFile(); File createSourceFile = new File(dir + SOURCE_TEST_FILE); createSourceFile.createNewFile(); updateFileHandle(createFile, TEST_DATA_1, false); updateFileHandle(createFile, TEST_DATA_2, false); updateFileHandle(createFile, TEST_DATA_3, false); appendFileContents(createFile, createSourceFile); updateFileHandle(createFile, null, true); deleteDirectory(dir); }
public static void updateFileHandle(File inputFile, String contentTobeAdded, boolean isClose) throws IOException { List<FileWriter> fileWriterStore = new ArrayList<>(); FileWriter fileWriter = new FileWriter(inputFile, true); fileWriterStore.add(fileWriter); PrintWriter outputPrintWriter = new PrintWriter(fileWriter, true); if (!isClose) { outputPrintWriter.write(contentTobeAdded); outputPrintWriter.flush(); outputPrintWriter.close(); } else { for (FileWriter curWriter : fileWriterStore) { curWriter.flush(); curWriter.close(); curWriter = null; } } }
FileSystemUtil { public static void updateFileHandle(File inputFile, String contentTobeAdded, boolean isClose) throws IOException { List<FileWriter> fileWriterStore = new ArrayList<>(); FileWriter fileWriter = new FileWriter(inputFile, true); fileWriterStore.add(fileWriter); PrintWriter outputPrintWriter = new PrintWriter(fileWriter, true); if (!isClose) { outputPrintWriter.write(contentTobeAdded); outputPrintWriter.flush(); outputPrintWriter.close(); } else { for (FileWriter curWriter : fileWriterStore) { curWriter.flush(); curWriter.close(); curWriter = null; } } } }
FileSystemUtil { public static void updateFileHandle(File inputFile, String contentTobeAdded, boolean isClose) throws IOException { List<FileWriter> fileWriterStore = new ArrayList<>(); FileWriter fileWriter = new FileWriter(inputFile, true); fileWriterStore.add(fileWriter); PrintWriter outputPrintWriter = new PrintWriter(fileWriter, true); if (!isClose) { outputPrintWriter.write(contentTobeAdded); outputPrintWriter.flush(); outputPrintWriter.close(); } else { for (FileWriter curWriter : fileWriterStore) { curWriter.flush(); curWriter.close(); curWriter = null; } } } private  FileSystemUtil(); }
FileSystemUtil { public static void updateFileHandle(File inputFile, String contentTobeAdded, boolean isClose) throws IOException { List<FileWriter> fileWriterStore = new ArrayList<>(); FileWriter fileWriter = new FileWriter(inputFile, true); fileWriterStore.add(fileWriter); PrintWriter outputPrintWriter = new PrintWriter(fileWriter, true); if (!isClose) { outputPrintWriter.write(contentTobeAdded); outputPrintWriter.flush(); outputPrintWriter.close(); } else { for (FileWriter curWriter : fileWriterStore) { curWriter.flush(); curWriter.close(); curWriter = null; } } } private  FileSystemUtil(); static void appendFileContents(File toAppend, File srcFile); static String readAppendFile(String toAppend, String spaces); static void updateFileHandle(File inputFile, String contentTobeAdded, boolean isClose); }
FileSystemUtil { public static void updateFileHandle(File inputFile, String contentTobeAdded, boolean isClose) throws IOException { List<FileWriter> fileWriterStore = new ArrayList<>(); FileWriter fileWriter = new FileWriter(inputFile, true); fileWriterStore.add(fileWriter); PrintWriter outputPrintWriter = new PrintWriter(fileWriter, true); if (!isClose) { outputPrintWriter.write(contentTobeAdded); outputPrintWriter.flush(); outputPrintWriter.close(); } else { for (FileWriter curWriter : fileWriterStore) { curWriter.flush(); curWriter.close(); curWriter = null; } } } private  FileSystemUtil(); static void appendFileContents(File toAppend, File srcFile); static String readAppendFile(String toAppend, String spaces); static void updateFileHandle(File inputFile, String contentTobeAdded, boolean isClose);  }