Byte[]완전한 파일을 나타내는 배열을 파일에 쓰려고   합니다.
클라이언트의 원본 파일은 TCP를 통해 전송 된 다음 서버에서 수신됩니다. 수신 된 스트림은 바이트 배열로 읽은 다음이 클래스에 의해 처리되도록 전송됩니다.
이것은 주로 수신 TCPClient이 다음 스트림에 대한 준비를하고 수신단을 처리 단에서 분리하기위한 것이다.
FileStream클래스는 인수 나 (당신이 그것에 바이트를 작성할 수 않는) 다른 스트림 객체로 바이트 배열을지지 않습니다.
원본과 다른 스레드 (TCPClient가있는 스레드)로 처리를 수행하려고합니다.
이것을 구현하는 방법을 모르겠습니다. 어떻게 시도해야합니까?
답변
질문의 첫 문장을 바탕으로 : ” 완전한 파일 을 나타내는 Byte [] 배열을 파일 에 쓰려고 합니다.”
최소 저항 경로는 다음과 같습니다.
File.WriteAllBytes(string path, byte[] bytes)
여기에 문서화 :
답변
BinaryWriter객체 를 사용할 수 있습니다 .
protected bool SaveData(string FileName, byte[] Data)
{
    BinaryWriter Writer = null;
    string Name = @"C:\temp\yourfile.name";
    try
    {
        // Create a new stream to write to the file
        Writer = new BinaryWriter(File.OpenWrite(Name));
        // Writer raw data                
        Writer.Write(Data);
        Writer.Flush();
        Writer.Close();
    }
    catch
    {
        //...
        return false;
    }
    return true;
}
편집 : 죄송합니다, finally부품을 잊어 버렸습니다 … 독자의 연습으로 남았습니다. 😉
답변
정적 방법이 있습니다 System.IO.File.WriteAllBytes
답변
System.IO.BinaryWriter스트림을 사용 하여이 작업을 수행 할 수 있습니다 .
var bw = new BinaryWriter(File.Open("path",FileMode.OpenOrCreate);
bw.Write(byteArray);
답변
FileStream.Write (byte [] 배열, int offset, int count)를 사용할 수 있습니다 그것을 쓰는 방법.
배열 이름이 “myArray”이면 코드가됩니다.
myStream.Write(myArray, 0, myArray.count);
답변
그래, 왜 안돼?
fs.Write(myByteArray, 0, myByteArray.Length);
답변
BinaryReader를 사용해보십시오.
/// <summary>
/// Convert the Binary AnyFile to Byte[] format
/// </summary>
/// <param name="image"></param>
/// <returns></returns>
public static byte[] ConvertANYFileToBytes(HttpPostedFileBase image)
{
    byte[] imageBytes = null;
    BinaryReader reader = new BinaryReader(image.InputStream);
    imageBytes = reader.ReadBytes((int)image.ContentLength);
    return imageBytes;
}
