Skip to content

File stream

Najna Abdulla

Asked Sep 2, 2014, 8:58 PM EDT1 answer
Share
LinkedInX
Code
 using (FileStream fs = File.Create(path))
            {
  AddText(fs, "This is some text");
                AddText(fs, "This is some more text,");
                AddText(fs, "\r\n and this is on a new line");
 for (int i = 1; i < 120; i++)
                {
                    AddText(fs, Convert.ToChar(i).ToString());

                }
            }
C#
private static void AddText(FileStream fs, string value)
        {
            byte[] info = new UTF8Encoding(true).GetBytes(value);
            fs.Write(info, 0, info.Length);
        }
 
Anyone plz understand me the writing of data to byte array 

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    this AddText function is basically picking the value and converting into bytes and then it's storing into byte[] info, e.g.,
            ascii
    A=>65
    B=>66

    so if there is AB written in value then it'll be 6566 and not it'll convert this 65 into byte and 66 into bytes which will is binary language.

    hope this helps.

    Please click checkbox "This is correct answer" if you find it helpful!
    0