UWP Read write File -StorageFile
//
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的更多相关文章
- win10 UWP 剪贴板 Clipboard
win10 UWP 剪贴板 Clipboard使用Windows.ApplicationModel.DataTransfer.Clipboard 设置文本 DataPackage dataPackag ...
- win10 UWP读写文件
C# uwp应用的文件读写最常见错误就是没有权限. 而最简单的方法是对已知的文件路径进行访问 已知的文件路径常见的是自身的路径 权限这个和之前不同,UWP读写文件多用StorageFile来读写文件 ...
- win10 uwp 活动磁贴
本文翻译:https://mobileprogrammerblog.wordpress.com/2015/12/23/live-tiles-and-notifications-in-universal ...
- UWP 使用Windows.Web.Http命名空间下的HttpClient使用post方法,上传图片服务器
1.从相册里面选取图片 /// <summary> /// 1.1 从相册里面选取图片 /// </summary> /// <param name="send ...
- UWP 剪贴板 Clipboard
Clipboard使用Windows.ApplicationModel.DataTransfer.Clipboard 设置文本 DataPackage dataPackage = new DataPa ...
- 【Win10应用开发】通过拖放来打开文件
除了可以使用XXXFilePicker来浏览文件外,其实在UWP APP中,也可以向传统Windows窗口一样,通过拖放的方式来打开文件. 处理过程和WPF的原理差不多,毕竟都是一脉相承,于是,在学习 ...
- 2018-9-30-win10-UWP-剪贴板-Clipboard
原文:2018-9-30-win10-UWP-剪贴板-Clipboard title author date CreateTime categories win10 UWP 剪贴板 Clipboard ...
- 2018-2-13-win10-uwp-活动磁贴
title author date CreateTime categories win10 uwp 活动磁贴 lindexi 2018-2-13 17:23:3 +0800 2018-2-13 17: ...
- win8 中实现断点续传
1) Resume method does resume on cases where resume is possible. Meaning if the server accepts range- ...
随机推荐
- 5.servlet 上传文件
一.maven依赖 <dependency> <groupId>commons-fileupload</groupId> <artifactId>com ...
- 借助System.Linq.Dynamic, IQueryable根据排序字符串排序
在使用Entity Framework时,若有多个排序,需要OrderBy (OrderByDescending)再ThenBy (ThenByDescending) 假设需要根据Name升序排序,再 ...
- 转:Window_Open详解
引:Window_Open详解一.window.open()支持环境:JavaScript1.0+/JScript1.0+/Nav2+/IE3+/Opera3+ 二.基本语法:window.op ...
- NSOperation的使用细节 [3]
NSOperation的使用细节 [3] 这一节我们来写自定义concurrent的operation,自定义concurrent的operation稍微有点复杂,需要按照某些既定的步骤编写才可以完成 ...
- Man's Best Friend: The Science Behind the Dog and Human Relationship
http://info.thinkfun.com/stem-education/mans-best-friend-the-science-behind-the-dog-and-human-relati ...
- c++ 数组操作(转)
转自 http://www.cnblogs.com/kykuaileren/archive/2011/09/04/2166646.html 一.数组定义和初始化 1: 一维数组初始化: 2: 标准方式 ...
- UNIX日期与时间
日期和时间 UINX系统内部有一个变量记录自开机以来经过的时间.从用户的角度,UNIX时间函数分为3类: 度量进程已使用CPU时间的函数: 给出绝对时间或日历时间的函数: 设置闹钟.定时器以及睡眠的函 ...
- spring-springmvc-hibernate项目小结
1. web.xml中别忘记加入spring监听器 <listener> <listener-class>org.springframework.web.context.Con ...
- 一、动态网络编程的概念 二、Tomcat服务器搭建 三、Servlet组件介绍
一.动态网络编程的概念 动态网页:结合了HTML以外的高级程序编程语言和数据库技术生成的页面. 动态网页编程技术: ASP,PHP,JSP HTTP协议:规范浏览器和服务器之间通信的数据格式. 浏览器 ...
- fun()可拆分赋值 fun()可以拆, 变成 fun 和 括号, fun 可以赋值
2. 函数名可以赋值给其他变量 ---> 就是 func()可以拆 def fun (): print("哈哈") a = fun # 拆分 fun()的 fu ...