B4J Question File to chunk of bytes

EnriqueGonzalez

Expert
Licensed User
Longtime User
Hi!

I have attempted several options but neither prospered, i have an X file with lets say 32mb i have to divide the file in chunks of 6mb each except the last one that would be the residual of 32/6 = 2Mb, that means 6 chunks.

any tip would be greatly appreciated.

An extra level of difficulty would be to read the file non secuentaly, that means, get the first chunk, do some stuff in other functions and later come back and read again the file for the second chunk.

thank you!
 

EnriqueGonzalez

Expert
Licensed User
Longtime User
well.. this is odd i found it like this (without the extra level of difficulty)

B4X:
Dim ins As InputStream = File.OpenInput(File.GetFileParent(f),File.GetName(f))

for i = 0 to 5 
      Dim buff(Min(ins.BytesAvailable,1024*1024*6)) As Byte
      ins.ReadBytes(buff,0 * i,Min(ins.BytesAvailable,1024*1024*6))

'buff contains the chunks. 
next
 
Upvote 0
Top