I have a requirement where I have to retrieve the contents from excel rows, do some operations write the response in same excel rows using Java class. So I decided to store t开发者_如何学运维he response in memory and write it once. Is it advisable or I have write them in to file for every response? Please advice me the best approach.
P.N: The excel file will have more than 1000 rows with three individual work sheets.
I would keep it simple and keep everything in memory and write down the complete file when finished unless the dataset is to be very large. But as Excel itself keeps everything in memory you should have no problem (at least given todays computers with several GB of RAM).
Memory is inexpensive, programmers are not smile
Since File I/O operations are a bit expensive, it's advisable to go for a single write as you've done already, assuming each and every row is independent of the other. but, I'd go with a fixed no. of rows at a time, say 100/150, instead of writing all at once, because any operation failure on a single row might cause an exception, affecting the rows processed already.
It depends on the requirements. Do the changes have to be reflected in the Excel file as soon as they are made? If yes, then you'll have no choice but to write the file to disk after each change. If there's no problem on updating the file only after all changes are applied (or a "save" operation is invoked), then storing the spreadsheet data on memory is a better idea.
精彩评论