HiveBrain v1.2.0
Get Started
← Back to all entries
patterncsharpCritical

Can a Byte[] Array be written to a file in C#?

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
arraybytefilecanwritten

Problem

I'm trying to write out a Byte[] array representing a complete file to a file.

The original file from the client is sent via TCP and then received by a server. The received stream is read to a byte array and then sent to be processed by this class.

This is mainly to ensure that the receiving TCPClient is ready for the next stream and separate the receiving end from the processing end.

The FileStream class does not take a byte array as an argument or another Stream object ( which does allow you to write bytes to it).

I'm aiming to get the processing done by a different thread from the original ( the one with the TCPClient).

I don't know how to implement this, what should I try?

Solution

Based on the first sentence of the question: "I'm trying to write out a Byte[] array representing a complete file to a file."

The path of least resistance would be:

File.WriteAllBytes(string path, byte[] bytes)


Documented here:


System.IO.File.WriteAllBytes - MSDN

Code Snippets

File.WriteAllBytes(string path, byte[] bytes)

Context

Stack Overflow Q#381508, score: 852

Revisions (0)

No revisions yet.