Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

[C#] How to write and read bytes ?

I've got byte[] lol = bunch of stuff
Length: {byte[64]}

saving it to conf.conf using:
Code
public static void writebytes(byte[] bytes, string path)
    {
  using (BinaryWriter binWriter =
  new BinaryWriter(File.Open(path, FileMode.Create)))
  {
  binWriter.Write(bytes);
  }
    }

Then I load it in using:
Code
public static byte[] Read(string path)
    {
  try { return File.ReadAllBytes(path); }
  catch { return null; }
    }

And then the Length is {byte[108]}

wtF? Is that because the filename is also in there? How i retreive the stuff i just saved ? !
(Jul 30, 2011 02:47 PM)sn4pcr4k Wrote:  I've got byte[] lol = bunch of stuff
Length: {byte[64]}

saving it to conf.conf using:
Code
public static void writebytes(byte[] bytes, string path)
    {
  using (BinaryWriter binWriter =
  new BinaryWriter(File.Open(path, FileMode.Create)))
  {
  binWriter.Write(bytes);
  }
    }

Then I load it in using:
Code
public static byte[] Read(string path)
    {
  try { return File.ReadAllBytes(path); }
  catch { return null; }
    }

And then the Length is {byte[108]}

wtF? Is that because the filename is also in there? How i retreive the stuff i just saved ? !

How are you trying to use it?
Try adding binWriter.Flush(); after you have written your data.
Thanks for the help, made a very stupid mistake. I should look at my code longer next time.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by zNinjaApr 5, 2020 01:24 PM 3 144 Apr 5, 2020 01:24 PM
Last Post: Mysticism
[C#] by mesticJan 13, 2019 06:36 PM 6 378 Jan 13, 2019 06:36 PM
Last Post: mestic
[C#] by gigajewJul 26, 2018 07:42 PM 1 282 Jul 26, 2018 07:42 PM
Last Post: techcrunch