i want append 8 bytes of my info to first of stream in sending file. i use NetworkStream and my code is this:
Stream Fs = File.OpenRead("filepath");
Byte[] buffer = new Byte[Fs.Length];
Fs.Read(buffer, 0, buffer.Length);
NetworkStream serverStream = clientSocket.GetStream();
serverStream.Write(buffer, 0, buffer.Length);
serverStream.Close();
How can i add my strings? thanks
Simply add an extra Write call before the one you've got. Write the 8 bytes first and then write the file contents.
By the way, if you're going to read the entire file into a byte array then don't use those first three lines (which fail to close the FileStream by the way). Just call File.ReadAllBytes and do it all in one line.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.