I used a simple code from online code and I was able to call the method in the code in a for loop and passing it data and row number. The file is created properly, the file's size (after refreshing my file explorer) is changed upon each insert but when i am done I open the file and I can only see the first row in there and the moment i close it the size of the file decreases from 1.5MB to 5bytes. I opened the 1.5 MB file in notepadd++ (ofcourse it opened with byte characters) I could actually see the data that i have been writing into the file besides the first row, All my rows were there. but when i open in excel it doesnt.
Is there some thing I am missing here. At each insert into the excel file I am doing this :
fileOutputStream = new FileOutputStream(fileName,true);
sampleWorkbook.write(fileOutputStream);
and after that in the finally block of the try block :
finally {
/**
* Close the fileOutputStream.
*/
try {
if (fileOutputStream != null) {
fileOutputStream.flush();
fileOutputStream.close();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
but if the file size is changing and I can view the data in a notepad why is excel treating the rows other than the first one as temporary data (that is what I'm assuming it's doing as it reverts back to only 5 bytes when I close the file)? What's wrong here?
Thanks for your help, in advance.
syed.