visual studio 2010 - unable to display contents byte[] properly on to a text box in c# -


i trying display byte[] in text box, first reading encrypted info file temp.enc byte array

filestream f = file.openread("temp.enc"); byte[] b = new byte[f.length];//length 32 bytes f.read(b, 0, convert.toint32(f.length)); f.close(); 

second try display content on text box, when run program dont see complete data. displays first 23 bytes of data

outputfiletextbox.text = system.text.encoding.default.getstring(b); 

how ever if use same byte array again write info file, have 32bytes written on file

binarywriter swenc = new binarywriter(file.openwrite("encypt.txt")); swenc.write(b); swenc.close(); 

this c# windows application, m not sure doing wrong.

be sure read , write in same format. looks reading in text using whatever default encoding is, write in binary format.

here sample code writes in same format reads in:

    private string readfile(string filename)     {         var sb = new stringbuilder();         if (system.io.file.exists(filename))         {             using (var f = system.io.file.openread(filename))             {                 var b = new byte[f.length];                 var len = f.read(b, 0, b.length);                 while ((-1 < len) && (len == b.length))                 {                     sb.append(system.text.encoding.utf8.getstring(b, 0, len));                     len = f.read(b, 0, b.length);                 }             }         }         return sb.tostring();     }      private void writefile(string filename, string data)     {         using (var f = system.io.file.openwrite(filename))         {             var b = system.text.encoding.utf8.getbytes(data);             f.write(b, 0, b.length);         }     } 

also, of text characters non-printing values (carriage returns, start of field, end of field, etc.).

consider of non-displayable values below decimal 32 value in following ascii chart:

ascii chart


Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -