Home > Back-end >  Java IO flow external modified to read again
Java IO flow external modified to read again

Time:09-21

In the same thread, open the debug mode (or use thread to sleep), using IO stream read from the file content, and then modify the file content, perform the read method again, found that the content of the two reads all the same, that is to say, the second is read or the original content, in the case of not restart the program, there are ways to do read the latest data, it looks like the IO stream bugs,
 public class Demo {

Public static String read (the File File) {
Byte [] bytes=null;
Try {
FileInputStream fin=new FileInputStream (file);
Int the available=fin. The available ();
Bytes=new byte [available];
Fin. Read (bytes);
} the catch (IOException e) {
e.printStackTrace();
}
Return a new String (bytes);
}

Public static void main (String [] args) {
File the File=new File (" C: \ \ Users \ \ Administrator \ \ Desktop \ \ dd \ \ SRC \ \ 123. TXT ");
The String content=read (file);
System. The out. Println (" content="+ content);
The content=read (file);
System. The out. Println (" content="+ content);
}
}
  • Related