If we want to read a file into the StringBuffer and write the new file, the new file MD5 value needs to remain the same (the new file is guaranteed to be identical to the source file),
We need to append the line break when manipulating StringBuffer:
1StringBuffer SB =NewStringBuffer ();2Reader rd =NULL;3BufferedReader br =NULL;4 5RD =NewFileReader ("e:/" is a ladies ' boy. html ");6BR =NewBufferedReader (RD);7String data =NULL;8 while(data = Br.readline ())! =NULL) {9 sb.append (data);TenSb.append ("\ r \ n");//stringbuffer Add a newline character when attaching content One A //The following are the Java newline characters under each operating system - /// R Mac - /// N unix/linux the ///r/n Windows - -}
This way, you can guarantee that MD5 will not change when you write to a new file using FileWrite.
JAVA file read Write MD5 value unchanged method