//

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. Python DDT(data driven tests)模块心得

    关于ddt模块的一些心得,主要是看官网的例子,加上一点自己的理解,官网地址:http://ddt.readthedocs.io/en/latest/example.html ddt(data driv ...

  2. leetcode 刷题

    176:第二高的薪水 offset ) as secondhighestsalary; ---去掉第一个,再从第一个开始 177:第N高的薪水 ------相关子查询:子查询中引用了外层查询所引用表的 ...

  3. MySQL字符存储:charset-unicode-sets

    https://dev.mysql.com/doc/refman/8.0/en/charset-unicode-sets.html 10.10.1 Unicode Character Sets MyS ...

  4. [UI] 精美UI界面欣赏[9]

    精美UI界面欣赏[9]

  5. win7下使用手动安装composer

    假设我们的php放置在D:\php 目录下, 1.添加环境变量,桌面--> 我的电脑右键---->属性 2.点击高级系统设置 3.点击环境变量 4.选择path,在变量值里面追加内容:  ...

  6. python -wordcloudan云词安装

    1安装网站:https://download.lfd.uci.edu/pythonlibs/u2yrk7ps/wordcloud-1.4.1-cp36-cp36m-win_amd64.whl 2安装过 ...

  7. nginx过一段时间出现400 Bad Request 错误的解决方法

    tomcat整合nginx成功后,等访问一段时间后,会出现 Bad Request (Invalid Hostname)的错误, 因为是已经成功的配置,所以判定可能是哪里的限制设置有问题,最后在官方网 ...

  8. MySQL-5.6版本GTID的主从复制

    mysql GTID Replication 一.GTID的概述: 1.全局事物标识:global transaction identifieds. 2.GTID事物是全局唯一性的,且一个事务对应一个 ...

  9. 1.1 What Is This Book About(这本书是关于什么的)

    CHAPTER 1 Preliminaries(预备知识) 1.1 What Is This Book About?(这本书是关于什么的) 这本书关心的是如何用Python对数据进行处理和清洗等操作. ...

  10. 【openjudge】【递推】例3.6 过河卒(Noip2002)

    [题目描述] 棋盘上A点有一个过河卒,需要走到目标B点.卒行走的规则:可以向下.或者向右.同时在棋盘上的某一点有一个对方的马(如C点),该马所在的点和所有跳跃一步可达的点称为对方马的控制点,如图3-1 ...