Hello all!
I have some troubles in saving a file by byte chunks, (will use in saving large file size.). My goal is to chunk the file bytes first into a certain size before writing.
I have this code:
FileConnection fc = (FileConnection) Connector.open("file.ext",
Connector.READ);
InputStream fis = (InputStream) fc.openInputStream();
byte[] fileData = new byte[(int) fc.fileSize()];
fis.read(fileData);
int MAX = 1024;
while(saved < fSize)
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
if((fSize - saved) < MAX){
MAX = fSize - saved;
}
for(int i = saved; i<MAX; i++){
baos.write(fileData[i]);
}
fout.write(baos.toByteArray());
saved += MAX;
}
A file is saved but not complete. I think only 1024 bytes are written. Any suggestions? Explanations?
Your help will be highly appreciated...
Thank you!