如何检查是否文件在Windows Store应用的存在? [英] How to check if file exists in a Windows Store App?

查看:125
本文介绍了如何检查是否文件在Windows Store应用的存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有检查文件是否在Windows商店应用中存在的任何其他方式?

 尝试
{
    var文件=等待ApplicationData.Current.LocalFolder.GetFileAsync(的test.xml);
    //也不例外意味着文件存在
}
赶上(FileNotFoundException异常前)
{
    //找出通过例外
}


解决方案

据<一个公认的答案href=\"http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/1eb71a80-c59c-4146-aeb6-fefd69f4b4bb/\">this帖子,还有目前没有其他办法。但是,文件IO团队正在考虑改变的API,以便返回null,而不是抛出异常。

从链接的帖子引用:


  

目前,检查文件是否存在的唯一方法就是赶
  FileNotFoundException异常。正如已经指出的具有一个明确的
  检查并开口是竞争条件,因此我不期待
  那里是任何文件存在API的补充。我相信,文件IO队
  (我不是那支球队,所以我不知道,但肯定这就是我
  听说)也在考虑由该API返回NULL,而不是抛出
  如果该文件不存在。


Is there any other way of checking whether a file exists in a Windows Store app?

try
{
    var file = await ApplicationData.Current.LocalFolder.GetFileAsync("Test.xml");
    //no exception means file exists
}
catch (FileNotFoundException ex)
{ 
    //find out through exception 
}

解决方案

According to the accepted answer in this post, there is no other way at the moment. However, the File IO team is considering changing the the api so that it returns null instead of throwing an exception.

Quote from the linked post:

Currently the only way to check if a file exists is to catch the FileNotFoundException. As has been pointed out having an explicit check and the opening is a race condition and as such I don't expect there to be any file exists API's added. I believe the File IO team (I'm not on that team so I don't know for sure but this is what I've heard) is considering having this API return null instead of throwing if the file doesn't exist.

这篇关于如何检查是否文件在Windows Store应用的存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆