Hi
Member 13142768
,
You are reading and writing straight-away. You need to store the items that you read in memory first. For this you can use a generic
list
. The following lines may change:
while ((bytesRead =
stream.Read(buffer, 0, 1024)) > 0)
{
writeStream.Write(buffer, 0, bytesRead);
}
To:
List<byte[]> StrList = new List<byte[]>();
while ((bytesRead =
stream.Read(buffer, 0, 1024)) > 0)
{
StrList.Add(buffer);
}
That is, you are reading the entire binary contents in a list as byte array entities. But I am still not sure about the contents of your file as you forgot to answer that.
After sorting you need to write the contents of the list.
The built-in
sort
method of list will not work here as it has binary byte array. You will need
IComparer
interface to assist. Here is a good solution to such sorting:
c# - Sorting list of list of bytes or list of byte arrays - Stack Overflow[
^]