public static void write2File(List<String> writeContent, String path, String flagStr) throws IOException, URISyntaxException {
File outFile = File.createTempFile("fileTmp", ".tmp");
File testFile = new File(path);
FileInputStream fis = new FileInputStream(testFile);
BufferedReader in = new BufferedReader(new InputStreamReader(fis));
FileOutputStream fos = new FileOutputStream(outFile);
PrintWriter out = new PrintWriter(fos);
String thisLine;
outFile.deleteOnExit();
while ((thisLine = in.readLine()) != null) {
if (thisLine.equals(flagStr)) {
writeContent.forEach(s-> {
out.println(s);
});
}
out.println(thisLine);
}
out.flush();
out.close();
in.close();
testFile.delete();
outFile.renameTo(testFile);
}