When both the output and input streams are opened, the text content disappears.
When you open both the output and input streams for a text file, if you use the API accidentally, you will find that the output stream output is empty for the following reasons:
Public static void main (String [] args) {FileInputStream FD = null; FileOutputStream fos = null; try {File file = new File ("D: // test.txt "); FS = new FileInputStream (file);/*** new FileOutputStream (file) * new FileOutputStream (file, true) append mode * if no append mode is selected, the contents of the original file will be cleared, such as FileWriter (which is internally maintained by FileOutputStream... */Fos = new FileOutputStream (file); byte [] B = new byte [1024]; int index = 0; while (index = FCM. read (B)> = 0) {System. out. println (new String (B, 0, index);} // "\ r \ n" is the line break fos. write ("\ r \ ntest ". getBytes ();} catch (FileNotFoundException e) {e. printStackTrace ();} catch (IOException e) {e. printStackTrace ();} finally {try {if (FS! = Null & fos! = Null) {fos. close (); FCM. close () ;}} catch (IOException e) {e. printStackTrace ();}}}