I agree, that would be by definition an exception state, where the
normal flow (check if file exists -> write to it) has been disrupted.
I have a little file name generation routine that does make use of the
FileNotFoundException though, out of pure convenience: (pseudo-code)
while (true) {
fileName = ...
try {
openFileInput(fileName);
} catch (FileNotFoundException e) {
// file doesn't exist, use this name
break;
}
}
Based on the top-rated answer here, re: staying in proper application
context:
http://stackoverflow.com/questions/2786655/test-if-file-exists
Paul
On Jan 18, 7:41 am, Kumar Bibek <[email protected]> wrote:
> Well, When someone deletes the file after you have created, and then you try
> to write into it, then the catch block comes into picture. But, I guess,
> that might not happen since the file would be locked. I am not sure though.
>
> But just in case, that happens, don't you think, it's actually an EXCEPTION?
>
> While trying to write into a file without checking if that file exists or
> not is ideal I would say.
>
> Kumar Bibekhttp://techdroid.kbeanie.comhttp://www.kbeanie.com
>
> On Tue, Jan 18, 2011 at 2:54 PM, appel <[email protected]> wrote:
> > So if I check with file.exists() and before I can call open some other
> > process deletes the file I should always crash? That doesn't sound very user
> > friendly to me.
>
> > --
> > 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]<android-developers%[email protected]>
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en
--
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