I want to create a file using byte[], which one is best.
byte[] content=File.ReadAllBytes(@"C:\ServiceLog.txt");
FileStream stream = new FileStream(@"C:\ServiceLog1.txt", FileMode.Create, FileAccess.ReadWrite);
stream.Write(content, 0, content.Length);
stream.Close();
or
File.WriteAllBytes(@"C:\12.txt",content);
If you have a
byte[], you might as well just useWriteAllBytesand let the wrapper method worry about the rest. TheStreamapproach is useful when you are (oddly enough) streaming the data, meaning: you might not know it all when you start writing. Since you do have thebyte[], just us it. However, in the general case, note thatbyte[]-based APIs may have more impact on memory thanStream-based APIs, especially for large content.