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- ...
随机推荐
- MATLAB filter2/conv2 函数在 Python 语言中的等价函数
MATLAB filter2 和 conv2 函数说明 在 MATLAB 中,filter2 函数实现二维数字滤波器.conv2 函数实现二维卷积. filter2(H, X, mode) 等价于 c ...
- 梯度下降法实现最简单线性回归问题python实现
梯度下降法是非常常见的优化方法,在神经网络的深度学习中更是必会方法,但是直接从深度学习去实现,会比较复杂.本文试图使用梯度下降来优化最简单的LSR线性回归问题,作为进一步学习的基础. import n ...
- 发布MVCIIS报错未能加载文件或程序
未能加载文件或程序集“System.Web.Http.WebHost, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e3 ...
- iOS设计模式 - 代理
iOS设计模式 - 代理 原理图 说明 1. 代理模式大家都用过,但用抽象基类NSProxy实现代理估计鲜有人用 2. 本人用NSProxy实现了代理模式,对于理解消息转发机制有点帮助 源码 http ...
- svn回退到具体的版本
svn回退到具体的版本 找到项目的版本号 命令行中输入相关命令 到指定地点找到项目即可
- opengl redbook Fatal Error in XXXXXX pixel format with necessary capabilities not found
随便运行书中的一个程序aaindex.c时出现了下面的错误:pixel format with necessary capabilities not found 解决方法: http://www.ed ...
- 第 6 章 C控制语句:循环
6.16.3 使用嵌套循环,按下面格式打印字母: F FE FED FEDC FEDCB FEDCBA #include <stdio.h> int main() { ; ); row ! ...
- October 05th 2017 Week 40th Thursday
Happiness is to find someone who can give you warm and share your life together. 幸福,就是找一个温暖的人过一辈子. Y ...
- 题解 P1018 【乘积最大】
题目链接:P1018 乘积最大 题面 今年是国际数学联盟确定的"2000――世界数学年",又恰逢我国著名数学家华罗庚先生诞辰90周年.在华罗庚先生的家乡江苏金坛,组织了一场别开生面 ...
- Redis info参数总结
可以看到,info的输出结果是分几块的,有Servers.Clients.Memory等等,通过info后面接这些参数,可以指定输出某一块数据. 下面是针对info的输出在旁边注释了,因为对Redis ...