What is better to use to create a file from byte []?

I want to create a file using byte [], which 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);
+5
source share
2 answers

If you have one byte[], you can simply use WriteAllBytesand let the wrapper method worry about everything else. The approach Streamis useful when you are (oddly enough) a data stream, that is: you may not know all this when you start writing. Since you have it byte[], we just have it. However, in the general case, note that based APIs byte[]may have a greater memory impact than based APIs Stream, especially for large content.

+9
source

, :

File.WriteAllBytes(@"C:\12.txt",content);

, .

+6

All Articles