How to insert text after a particular line of a file
问题 I have a file of 250 line. I wanted to insert some text after line 128. I only found that I can append a text at the end of file like try { PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("outfilename", true))); out.println("the text"); out.close(); } catch (IOException e) { //oh noes! } That is found on this post How to append text to an existing file in Java But with no mention to the line number or sth. 回答1: There's no way to insert text in the middle of a file because