There is a file, let it be Script.ps1 powershell. I need to consider it as parts and with each part produce some (add to another file remotely). The size of one part is valid 1Kb. I understand how to do it, but something doesn’t work out for me at all, please help. Approximate code

byte[] buffer; int size = 1024; FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read); { buffer = new byte[size]; int count; int sum = 0; while ((count = fileStream.Read(buffer, sum, size - sum)) > 0) { sum += count; //Дальше преобразую buffer в строку и уже пытаюсь работать со строкой } } 

Tried to do, too, through the number of pieces

 long file_count = filestrim.Length / size; //дальше в цикле запускаю считывание 

but either I don’t move the carriage, or I prescribe it incorrectly, it doesn’t work as it should (

  • So it should not work ... - Qwertiy

1 answer 1

Read the description of the Read method, especially about the parameters of the https://msdn.microsoft.com/ru-ru/library/system.io.filestream.read(v=vs.110).aspx method you use it incorrectly. In your case, you need fileStream.Read (buffer, 0, size). Because FileStream, then each Read reads the next piece. "Carriage Shift" occurs automatically.