//

private void MainPage_Loaded(object sender, RoutedEventArgs e)

{

GetFileAsync();

}

public async void GetFileAsync()

{

        Uri uri = new Uri("ms-appx:///Resources/t.txt");
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(uri);
string s;
using (Stream stream = await file.OpenStreamForReadAsync())
{
using (StreamReader read = new StreamReader(stream))
{
s = read.ReadToEnd();
new MessageDialog("" + s, "title open file").ShowAsync(); }
} }

public async void testWriteFile2() {

        string file_name = "test.txt";
StorageFolder folder = ApplicationData.Current.LocalFolder;
StorageFile file= await folder.CreateFileAsync(file_name, CreationCollisionOption.ReplaceExisting);
using (Stream stream = await file.OpenStreamForWriteAsync())
{
using (StreamWriter write = new StreamWriter(stream ))
{
write.Write("??0000000000000");
}
} } public async void WriteFileAsync()
{ Uri uri = new Uri("ms-appx:///Resources/t.txt");
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(uri);//??
string s;
using (Stream stream = await file.OpenStreamForWriteAsync())//System.UnauthorizedAccessException: Access is denied.
{
using (StreamWriter writer = new StreamWriter(stream))
{
writer.Write("ffffffffffff"+DateTime.Now );
new MessageDialog("write file ok", "title open file").ShowAsync(); }
} }
  •   $exception	{System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

    at System.IO.WindowsRuntimeStorageExtensions.d__3.MoveNext()

    --- End of stack trace from previous location where exception was thrown ---

    at System.IO.WindowsRuntimeStorageExtensions.d__3.MoveNext()

    --- End of stack trace from previous location where exception was thrown ---

    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

    at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()

    at App1.MainPage.d__4.MoveNext()} System.UnauthorizedAccessException

UWP Read write File -StorageFile的更多相关文章

  1. win10 UWP 剪贴板 Clipboard

    win10 UWP 剪贴板 Clipboard使用Windows.ApplicationModel.DataTransfer.Clipboard 设置文本 DataPackage dataPackag ...

  2. win10 UWP读写文件

    C# uwp应用的文件读写最常见错误就是没有权限. 而最简单的方法是对已知的文件路径进行访问 已知的文件路径常见的是自身的路径 权限这个和之前不同,UWP读写文件多用StorageFile来读写文件 ...

  3. win10 uwp 活动磁贴

    本文翻译:https://mobileprogrammerblog.wordpress.com/2015/12/23/live-tiles-and-notifications-in-universal ...

  4. UWP 使用Windows.Web.Http命名空间下的HttpClient使用post方法,上传图片服务器

    1.从相册里面选取图片 /// <summary> /// 1.1 从相册里面选取图片 /// </summary> /// <param name="send ...

  5. UWP 剪贴板 Clipboard

    Clipboard使用Windows.ApplicationModel.DataTransfer.Clipboard 设置文本 DataPackage dataPackage = new DataPa ...

  6. 【Win10应用开发】通过拖放来打开文件

    除了可以使用XXXFilePicker来浏览文件外,其实在UWP APP中,也可以向传统Windows窗口一样,通过拖放的方式来打开文件. 处理过程和WPF的原理差不多,毕竟都是一脉相承,于是,在学习 ...

  7. 2018-9-30-win10-UWP-剪贴板-Clipboard

    原文:2018-9-30-win10-UWP-剪贴板-Clipboard title author date CreateTime categories win10 UWP 剪贴板 Clipboard ...

  8. 2018-2-13-win10-uwp-活动磁贴

    title author date CreateTime categories win10 uwp 活动磁贴 lindexi 2018-2-13 17:23:3 +0800 2018-2-13 17: ...

  9. win8 中实现断点续传

    1) Resume method does resume on cases where resume is possible. Meaning if the server accepts range- ...

随机推荐

  1. 使用DataTables插件与后台对接表格

    function getResults(){ var callResults = $.ajax({ url: "....", //接口url type: "GET&quo ...

  2. zabbix系列之二——安装

    1Getting zabbix Four ways of getting: Index Option note 1 Install it from the distribution packages ...

  3. mysql数据库的常用命令总结及具体操作步骤

    从头复习一下数据库的语法 use database;  --- 使用数据库 show databases/tables --- 查看所有的数据库/表 desc table; --- 查看表的结构 cr ...

  4. 定制选择范围的按钮RangeButton

    定制选择范围的按钮RangeButton 效果: 源码: RangeButton.h 与 RangeButton.m // // RangeButton.h // PulsingView // // ...

  5. SQL脚本运行

    $v=New-Object -ComObject wscript.shell#也可以使用反单引号(`)字符来强制PowerShell将单引号或双引号解释为文本,0不显示命令提示符窗口$v.run(&q ...

  6. idea指定SpringBoot启动.properties文件

    比如我的项目下有2个.properties文件,一个是application.properties,一个是application-local.properties,在本地的时候想指定用applicat ...

  7. November 21st 2016 Week 48th Monday

    A bird is known by its note, and a man by his talk. 闻其声而知鸟,听其言而知人. Listen to what a man talks, watch ...

  8. November 9th 2016 Week 46th Wednesday

    Love is the poetry of the scenes. 爱是感官之诗. Recently I always feel lonely, I badly hope that I can fin ...

  9. tyvj1953 Normal

    题目链接 正解:点分治+$FFT$. 很想吐槽一下$bzoj$,为什么搬了别的$oj$的题还设成权限题.. 首先我们考虑期望的线性性,即考虑每个点的贡献. 显然每个点的贡献就是它在点分树上的深度,所以 ...

  10. 【LGP4886 】快递员

    题目 好秒啊,真是一道神仙的点分治 于是我们来一个暴力的\(O(nlog^2n)\)的暴力统计吧 考虑计算每一个点作为快递中心时的答案 我们考虑在这个点成为分治重心时计算这个贡献 把这个贡献分成两部分 ...