0

The problem statement is: There is huge file having comma separated bytes. The file size is big enough that it cannot be stored in-memory. I want to read this file in small chunks of sliding window. I figured out how I can read file in chunks, but not am able to slide the window. For example, if file.txt has content:

{33,54,34,78,23,90,87.....}

first chunk should be : [33,54,34]

second chunk should be : [54,34,78]

third chunk should be : [34,78,23] and so on..

Here is the code to read chunk, but how I can slide window. File inputFile = new File("file.txt");

FileInputStream istream = new FileInputStream(inputFile);

BufferedInputStream in = new BufferedInputStream(istream);

int[] bytes = new byte[3];
int len;
while ((len = in.read(bytes)) != -1) {
          //do some action
        }
dev
  • 3
  • 2
  • 1
    Have you tried grabbing a pen and paper and writing down what each new value read is supposed to do? There are a few ways to do this, at least one of which should be fairly easy to figure out yourself. – Bernhard Barker Mar 30 '18 at 06:54
  • @Dukeling I know what to do with each value, that is not my question here. My question is how I can read from file where I can remove one byte from start and pick a new value from file, and ultimately size of array I am reading from file is same. – dev Mar 31 '18 at 17:05
  • Read one value at a time, then you can do the sliding window logic apart from that. There's a read method that returns one byte at a time. – Bernhard Barker Mar 31 '18 at 17:47

0 Answers0