.net - How to read content from application specific binary files in c# -
i trying read binary file's contents using c#. consider application can have files specific application, meaning users can open these files using application. application may not give full access user, e.g., user may granted read-only access. want allow user open file associated application , allow user edit file. have tried following:
// read file <bits> var fs = new filestream(@"c:\temp\test.appx", filemode.open); var len = (int)fs.length; var bits = new byte[len]; fs.read(bits, 0, len); // dump 16 bytes per line (int ix = 0; ix < len; ix += 16)  {     var cnt = math.min(16, len - ix);     var line = new byte[cnt];     array.copy(bits, ix, line, 0, cnt);     // write address + hex + ascii     console.write("{0:x6}  ", ix);     console.write(bitconverter.tostring(line));     console.write("  ");     // convert non-ascii characters .     (int jx = 0; jx < cnt; ++jx)         if (line[jx] < 0x20 || line[jx] > 0x7f) line[jx] = (byte)'.';             console.writeline(encoding.ascii.getstring(line)); }   however, not able read data application-specific binary file. there other way can read complete file contents?
i updated question :
d        ÿþÿ5c  : \ u s e r s \  v s   t e c h n  o s \ d e s k t  o p \ t r n  n g \ r w \  1 \ s e c - 3 5  . x p r  ÿÿ
 cprofileÿþÿ
    ²    çÂu° º£ì?         €aÀ           : 
: §èh. ÿ¡!ÀåÐ"ÛùÞ.À
  €aÀzd;ßoí Àt㥛 Ä -À     €aÀ¨wÊ2 Ä1 ÀÚ¬ú\me+À
  €aÀhpüs×ÀÊtÁ¨ ¤®)À     €aÀÄbi Þ1À®¶bÙý'À
  €aÀ°çŒ(mÀ0»' u&À     €aÀ¿}8 g„ÀƒÀÊ¡e¶$À
  €aÀÁÊ¡e¶sÀnÑ‘\ þ##À     €aÀd]Üf
i able read text in human readable format , can't remaining text corrupted data.
quick , dirty version. did small binary file have, , worked perfectly.
var file = file.readallbytes(filename);    //your byte array stuff, turn binary byte array memory aka bytearray  ... //more statements etc....  //reads bytearray readable txt file allow them read accordingly in english.  string result = system.text.encoding.utf8.getstring(bytearray)       
Comments
Post a Comment