Tobiah wrote: > I am opening a file for append using BufferedWriter. Each time the app > is run, more data is added to the file. At first a made a little class > representing the file and gave it a write() method that would take a > string > and send it out, then flush() the Writer. I was wondering when I should > close the file, or whether I really needed to. Will java [sic] close the > file > for me when the app goes away? Right now, since the writes are few and > far between, I'm just opening and closing the file each time I write > a line to it, but that seems really awkward. >
What does "seems awkward" mean, let alone "really" awkward? What harm does "awkward" cause? What's "awkward" is holding a resource like a file open for a really long time when you aren't using it. File handles are a finite resource. Like all such, you should manage them wisely. Assess the objective costs and benefits of the approach in the context where you use it. "Writes are few and far between", depending on what you mean by "few" and "far", could very well be a use case for closing the file between writes. Or not. At what point does "not few" and "not far" become significant enough to justify not closing the file? Almost certainly the non-measurable degree of "awkwardness" is not relevant. -- Lew -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

