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- ...
随机推荐
- ES6-let & const
let和const命令 let 它的用法类似于var,但是所声明的变量,只在let命令所在的代码块内有效. for(let i = 0; i < arr.length; i++){} 用let命 ...
- Python 面向对象(一)
面向过程编程 (Procedural Programming) Prodcedural programming uses a list of instructions to tell the comp ...
- HBase Scan流程分析
HBase Scan流程分析 HBase的读流程目前看来比较复杂,主要由于: HBase的表数据分为多个层次,HRegion->HStore->[HFile,HFile,...,MemSt ...
- JAVA 判断字符长度
/** * 判断姓名字符长度 * 字符串为空返回0:有中文返回中文字符数:无中文返回2 * @param CustomerSn * @return */ private Integer getName ...
- Oracle EBS 日记账
select b.status, h.je_source, (select USER_JE_CATEGORY_NAME from GL_JE_CATEGORIES where JE_CATEGORY_ ...
- SQL Server ->> 条件筛选做法之 -- IN(VALUE1,VALUE2,...)与INNER JOIN STRING_SPLIT()性能对比
在以逗号拼接而成的字符串,传入给IN字句的元素字符串中包涵了1400多个元素 两种做法分别为 AND e.ssPfCityId IN ( SELECT CAST(value AS INT) FROM ...
- 模仿SDWebImage实现异步加载图片
模仿SDWebImage实现异步加载图片 SDWebImage想必大家都不陌生吧,要实现它的图片异步加载功能这个还是很简单的. 注意:此处我只实现了异步加载图片,并没有将文件缓存到本地的打算哦:) 源 ...
- [翻译] DCPathButton
DCPathButton https://github.com/Tangdixi/DCPathButton DCPathButton 2.0 is a menu button for iOS. Des ...
- UNIX高级环境编程(5)Files And Directories - 文件相关时间,目录文件相关操作
1 File Times 每个文件会维护三个时间字段,每个字段代表的时间都不同.如下表所示: 字段说明: st_mtim(the modification time)记录了文件内容最后一次被修改的时 ...
- Hadoop HBase概念学习系列之HBase表的一些设置(强烈推荐好好领悟)(十三)
压缩格式:默认压缩格式是NONE.可选值有GZ.LZO.SNAPPY. 版本数:HBase默认定义为3个版本. 以秒为单位的存活时间TTL:使用对象是行中的列簇,一旦达到过期时间,HBase会删除这些 ...