How do I find out if a file is already created in a StorageFolder

北城余情 提交于 2019-12-23 09:49:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!