问题
If I have a metro StorageFolder, I can get a file using GetFileAsync(fileName).
However, how do I know if the file exists in the first place? Right now, I catch an exception but it does not seem like the right thing to do.
回答1:
According to Microsoft, they want us to catch the exception. The reasoning they gave me is that them providing a File.Exists API would open you up to race conditions where the file's existance might change between when you check and when you try to use the file. Because of that race condition, you have to write exception handling code anyways and once you've done that, there's little to be gained by calling a File.Exists API. I don't agree with this argument but it's what we're stuck with.
来源:https://stackoverflow.com/questions/10067220/how-do-i-find-out-if-a-file-is-already-created-in-a-storagefolder