Why byte array of .doc or .docx file in Java changes everytime the file is saved again in MS Word?
<p>I am trying to read a .doc or .docx file in a byte Array in Java. I am not looking forward to use any third party APis like Apache POI, TIKA, doc4j, etc.
The code at its simplest level is:- </p>

<pre><code>Path file_path = Paths.get("D:\\", "myname3.doc");
    byte[] ByteArray= Files.readAllBytes(file_path);
    for(byte b : ByteArray){
        System.out.print(b);
    }
</code></pre>

<p>Code is working fine and I receive the byte array. However, when I open the same file again in MS Word, makes no changes, but save it again in the same drive with same contents, the byte array that I receive is totally different. I understand that differences in MetaData pertaining to modified time exists, but the byte Array is totally different, as if the whole content of file has been changed. (attaching the text files containing byte Array of both the iterations).
<a href="http://i.stack.imgur.com/iDysi.png" rel="nofollow">Difference in Byte Array</a></p>

<p>Is there a solution to this without using third party APIs?</p>

<p>Note:- I have gone through Word encoding format given at MS website, and also, looked at the endianness issues just in case. Also tried reading the file through FileInputStreamReader. </p>

<p>Note:- This program is working fine for Text files in ASCII format.</p>

<p>EDIT 1:- just to make the question lucid. When I read the .docx file which is saved twice at same location with dfferent name, the byte array is completely different when I read the file using the program above. I would like to know the reason behind this.</p>

<p>EDIT 2:- i tried reading the files in OffVis tool, there also, the raw bytes are different.</p>