1
Answer

Dividing the data in text file into smaller chunks

Ram Prasad

Ram Prasad

4y
1.8k
1
I am working on this program where I have defined a class value which takes data from a text file. Right now my program is taking the whole data, processes it and then is used in further calculation in Main().
 
I want to divide the incoming data into smaller data chunks and perform the calculation one by one.
For Ex: lets say I have 2048 bits in .txt file, this data gets divided into 4 chunks of 512 bits each. After division Chunk 1 is used in furhter calcualtion in Main(), after that program comes back o pick Chunk 2 and do the calculation and similar with Chunk 3 and Chunk 4. How can I do that? Please advise
 
public static byte[] GetValue()
{
 byte[] numbers = new byte[2048];
 using (FileStream fs = File.Open(@"C:\Users\file1.txt", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
using (BufferedStream bs = new BufferedStream(fs))
using (StreamReader sr = new StreamReader(bs))
{
string line;
while ((line = sr.ReadLine()) != null)
{
 for (int i = 0; i < 512; i++)
 {
 numbers[i] = Byte.Parse(line[i].ToString());
 }
 }
 }
 return numbers;
}
 
Answers (1)