Keep these lines outside for loop in the beginning :
FileOutputStream fos = new FileOutputStream(strFilePath);
DataOutputStream dos = new DataOutputStream(fos);
And close the OutputStream once write is complete. You can use finally()
and write dos.close();
in it.
In your code, for each iteration a new file is created and hence, old data is overwritten.