WinRT中不存在该文件时如何创建文件? [英] How to create a file when the file is not exist in WinRT?
本文介绍了WinRT中不存在该文件时如何创建文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要的
打开文件(如果存在),创建文件(如果不存在)
What I want
open a file if it exists, create it if it not exists
我编写的代码
try
{
return await folder.GetFileAsync(fileName);
}
catch (FileNotFoundException )
{
StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync(fileName);
return file;
}
发生什么错误
无法在catch子句的正文中等待
What the error
Cannot await in the body of a catch clause
如何制作?
推荐答案
Why not just call CreateFileAsync
and specify OpenIfExists
?
使用所需名称创建新文件或文件夹,或者如果已经存在具有该名称的文件或文件夹,则返回现有项目.
Create the new file or folder with the desired name, or returns an existing item if a file or folder already exists with that name.
这篇关于WinRT中不存在该文件时如何创建文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文