BufferedReader console = new BufferedReader(new InputStreamReader(System.in)); String file_1 = console.readLine(); String file_2 = console.readLine(); console.close(); BufferedWriter fw = new BufferedWriter(new FileWriter(file_1)); BufferedReader fr_1 = new BufferedReader(new FileReader(file_1)); BufferedReader fr_2 = new BufferedReader(new FileReader(file_2)); String str; while ((str = fr_2.readLine()) != null) fw.write(str); while ((str = fr_1.readLine()) != null) fw.write(str); fw.close(); fr_1.close(); fr_2.close(); My code is above and it solve the problem on the website. However, when I test it in intellj with two of my txt files, the result is strange. Only the file_2 add into file_1, and the original file_1 cannot write into the file_1. Can anyone please help me? Anyway, I tried FileWriter(file_1, true), and the file_1's context was writed into the file, however, the first line still remain the origin context. I know why there is still original context. What I really don't know is why I use FileWriter without append para, all things become strange?