I have read the data from an .docx file using stream reader and got the content in string and printed using Console.writeLine. This content is not same as that of content which i got using File.ReadAllBytes function for the same file.
And the codes are shown below
// first code
StreamReader streamReader = new StreamReader("D:\\sample.docx");
String text = streamReader.ReadToEnd();
Console.WriteLine(streamReader.CurrentEncoding);//it shows the ecoding as UTF8
byte[] array = Encoding.UTF8.GetBytes(text)
File.WriteAllBytes("D:\\file3.txt", array);
This is my output when I used the above code
PK ! ߤ�lZ [Content_Types].xml �(� ���n�0E�����Ub袪*�>�-R�{V��Ǽ��QU�
l"%3��3Vƃ�ښl �w%�=���^i7+���-d&�0�A�6�l4��L60#�Ò�S
O����X� �*��V$z�3��3������%p)O�^����5}nH"d�s�Xg�L�`���|�ԟ�|�P�rۃs�?�PW��tt4Q+��"�wa���|T\y���,N���U�%���-D/��ܚ��X�ݞ�(���<E��)�� ;�N�L?�F�˼��܉��<Fk� �h�y����ڜ���q�i��?�ޯl��i� 1��]�H�g��m�@����m� �� PK ! ��� N _rels/.rels �(�
// second code
byte[] x = File.ReadAllBytes("D:\\sample.docx");
File.WriteAllBytes("C:\\file3.txt", x);
Both the file contents are different. Is there any possible way of my first code to get the same content as that of second code?
This is my output when used ReadAllBytes
PK ! ߤÒlZ [Content_Types].xml ¢( ´”ËnÂ0E÷•ú‘·Ub袪*‹>–-Ré{Vý’Ǽþ¾QU‘
l"%3÷Þ3VƃÑÚšl µw%ë=–“^i7+Ù×ä-d&á”0ÞAÉ6€l4¼½L60#µÃ’ÍS
Oœ£œƒXø Ž*•V$z3„ü3à÷½Þ—Þ%p)Oµ^ “²×5}nH"dÙsÓXg•L„`´‰ê|éÔŸ”|—PrÛƒsðŽ?˜PWŽìtt4Q+ÈÆ"¦wa©‹¯|T\y¹°¤,NÛàôU¥%´úÚ-D/‘ÎÜš¢X¡Ýžÿ(¦¼<EãÛ)‘à ;çN„L?¯Fñ˼¤¢Ü‰˜¸<FkÝ ‘h¡yöÏæØÚœŠ¤Îqôi£ã?ÆÞ¯lÎià 1éÓ]›HÖgÏõm @ÈæÛûmø ÿÿ PK ! ‘·ï N _rels/.rels ¢(