Home > Back-end >  Java write method in the loop calls FileOutputStream why won't cover the file content?
Java write method in the loop calls FileOutputStream why won't cover the file content?

Time:10-28

Source of data in TXT file for the helloworld, finally the new generated file contents is helloworld.

Buffer the array size is 2, then each loop only to temp array into two characters, each call to the write method can only write two bytes, why not take cover before writing? The ouput constructor will not cover??

CodePudding user response:

Problem has been solved, see the write () method of source and found this method is additional written not cover written, step by step in the debug runtime found running through the output=new FileOutputStream (dest); After the content of the target file will be empty () when the file exists, and then call the write () method will buffer in the array data appended to the file

CodePudding user response:

That cover the destination file content not because call write () method, but because the output=new FileOutputStream (dest); This statement clear purpose file content
  • Related