位置: 编程技术 - 正文

Windows 8技巧:关于windows 8的文件管理 File创建和String Stream Buffer方式读写的(关闭windows怎么关)

编辑:rootadmin

推荐整理分享Windows 8技巧:关于windows 8的文件管理 File创建和String Stream Buffer方式读写的(关闭windows怎么关),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:windows8咋关机,关闭windows,这样您就能安全的关闭计算机,wind8怎么关机,windows8.1怎么关机,关闭windows怎么关,window8怎么关机,win8怎么关电脑,windows8.1怎么关机,内容如对您有帮助,希望把文章链接给更多的朋友!

  在本文中我们将学习Windows 8中的文件创建和多种读写方式以及设置文档库访问权限和文件类型的访问。

  当然我们需要做以下准备工作:

  首先:设置程序允许访问的文件位置为:"库文档",设置方法:点击”Package.appxmanifest“,然后选择”功能“选项卡,在功能列表中勾选”文档库访问“。如下图:

Windows 8技巧:关于windows 8的文件管理 File创建和String Stream Buffer方式读写的(关闭windows怎么关)

  其次:设置程序允许以上文件夹内的文件类型,本实例中设置为txt后缀的文件:设置方法:点击”Package.appxmanifest“,然后选择”声明“选项卡,在可用声明下拉列表中选择”文件类型关联“,点击”添加“按钮,并且在右边的列表中添加”支持的文件类型为.txt,并且设置名称为txt,当然你也可以继续添加允许访问dat文件等,如下图:

  准备工作做好了,我们需要创建一个项目,然后写入一下代码进行访问文件以及文件夹,创建文件和读写文件。

Xaml代码:复制代码代码如下:<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}"> <!--显示区--> <TextBlock HorizontalAlignment="Left" Margin=",,0,0" TextWrapping="Wrap" Text="文件名:" VerticalAlignment="Top" Height="" Width=""/> <TextBox HorizontalAlignment="Left" Margin=",,0,0" TextWrapping="Wrap" Text="test.txt" VerticalAlignment="Top" Width="" Name="tbFileName"/> <TextBox HorizontalAlignment="Left" Margin=",,0,0" TextWrapping="Wrap" Text="默认需要添加的文件内容" VerticalAlignment="Top" Width="" Name="tbContent"/> <TextBlock HorizontalAlignment="Left" Margin=",,0,0" TextWrapping="Wrap" Text="文件内容:" VerticalAlignment="Top" Height="" Width=""/> <TextBlock HorizontalAlignment="Left" Margin=",,0,0" TextWrapping="Wrap" Text="提示:" VerticalAlignment="Top" Height="" Width="" Name="tb_show"/> <!--创建文件以及普通string写入读取文本--> <Button Content="创建文件" HorizontalAlignment="Left" Margin=",,0,0" Name="btnCreateFile" VerticalAlignment="Top" Click="btnCreateFile_Click"/> <Button Content="写入string文件" HorizontalAlignment="Left" Margin=",,0,0" x:Name="btnWriteFile_Copy" VerticalAlignment="Top" Click="btnWriteFile_Copy_Click"/> <Button Content="读取string文件" HorizontalAlignment="Left" Margin=",,0,0" x:Name="btnReadFile" VerticalAlignment="Top" Click="btnReadFile_Click"/> <!--Buffer方式写入和读取--> <Button Content="写入Buffer数据" HorizontalAlignment="Left" Margin=",,0,0" x:Name="btnWriteBufferFile" VerticalAlignment="Top" Click="btnWriteBufferFile_Click" /> <Button Content="读取Buffer数据" HorizontalAlignment="Left" Margin=",,0,0" x:Name="btnReadBufferFile" VerticalAlignment="Top" Click="btnReadBufferFile_Click"/> <!--Stream方式写入和读取--> <Button Content="写入Stream数据" HorizontalAlignment="Left" Margin=",,0,0" x:Name="btnWriteStreamFile" VerticalAlignment="Top" Click="btnWriteStreamFile_Click" /> <Button Content="读取Stream数据" HorizontalAlignment="Left" Margin=",,0,0" x:Name="btnReadStreamFile" VerticalAlignment="Top" Click="btnReadStreamFile_Click"/> </Grid>cs代码:复制代码代码如下:/// <summary> /// An empty page that can be used on its own or navigated to within a Frame. /// </summary> public sealed partial class MainPage : Page {</p><p> public MainPage() { this.InitializeComponent(); }</p><p> /// <summary> /// Invoked when this page is about to be displayed in a Frame. /// </summary> /// <param name="e">Event data that describes how this page was reached. The Parameter /// property is typically used to configure the page.</param> protected override void OnNavigatedTo(NavigationEventArgs e) { }</p><p> //获取“库文档”文件夹 StorageFolder storageFolder = KnownFolders.DocumentsLibrary;</p><p> //创建文件以及普通string写入读取文本 private async void btnCreateFile_Click(object sender, RoutedEventArgs e) { StorageFile sf= await storageFolder.CreateFileAsync(this.tbFileName.Text.Trim(), CreationCollisionOption.ReplaceExisting); tb_show.Text = "提示:创建了文件--" + this.tbFileName.Text.Trim(); }</p><p> private async void btnWriteFile_Copy_Click(object sender, RoutedEventArgs e) { try { string writestr = this.tbContent.Text.Trim() + "text方式"; StorageFile sf = await storageFolder.GetFileAsync(this.tbFileName.Text.Trim()); await FileIO.WriteTextAsync(sf, writestr); tb_show.Text = "提示:文件写入成功,写入内容为-“" + writestr + "”"; } catch (Exception ex) { tb_show.Text = "提示:未找到该文件,请先创建文件"; } }</p><p> private async void btnReadFile_Click(object sender, RoutedEventArgs e) { try { StorageFile sf = await storageFolder.GetFileAsync(this.tbFileName.Text.Trim()); string filecontent= await FileIO.ReadTextAsync(sf,UnicodeEncoding.Utf8); tb_show.Text = "提示:文件以string方式读取成功,读取的内容为-“" + filecontent+"”"; } catch (Exception ex) { tb_show.Text = "提示:未找到该文件,请先创建文件"; } } //Buffer方式写入和读取 private async void btnWriteBufferFile_Click(object sender, RoutedEventArgs e) { try { string writestr = this.tbContent.Text.Trim() + "buffer方式"; StorageFile sf = await storageFolder.GetFileAsync(this.tbFileName.Text.Trim()); IBuffer buffer = GetBufferFromString(writestr); await FileIO.WriteBufferAsync(sf, buffer); tb_show.Text = "提示:文件写入成功,写入内容为-“" + writestr + "”"; } catch (Exception ex) { tb_show.Text = "提示:未找到该文件,请先创建文件"; } }</p><p> private async void btnReadBufferFile_Click(object sender, RoutedEventArgs e) { StorageFile sf = await storageFolder.GetFileAsync(this.tbFileName.Text.Trim()); IBuffer buffer = await FileIO.ReadBufferAsync(sf); using (DataReader dataReader = DataReader.FromBuffer(buffer)) { string filecontent = dataReader.ReadString(buffer.Length); tb_show.Text = "提示:文件以Buffer方式读取成功,读取的内容为-“" + filecontent + "”"; } }</p><p> //将String转为Buffer private IBuffer GetBufferFromString(String str) { using (InMemoryRandomAccessStream memoryStream = new InMemoryRandomAccessStream()) { using (DataWriter dataWriter = new DataWriter(memoryStream)) { dataWriter.WriteString(str); return dataWriter.DetachBuffer(); } } }</p><p> //Stream方式写入和读取 private async void btnWriteStreamFile_Click(object sender, RoutedEventArgs e) { try { string writestr = this.tbContent.Text.Trim() + "Stream方式"; StorageFile sf = await storageFolder.GetFileAsync(this.tbFileName.Text.Trim()); using (StorageStreamTransaction transaction = await sf.OpenTransactedWriteAsync()) { using (DataWriter dataWriter = new DataWriter(transaction.Stream)) { dataWriter.WriteString(writestr); transaction.Stream.Size = await dataWriter.StoreAsync(); // reset stream size to override the file await transaction.CommitAsync(); tb_show.Text = "提示:文件写入成功,写入内容为-“" + writestr + "”"; } } } catch (Exception ex) { tb_show.Text = "提示:未找到该文件,请先创建文件"; } }</p><p> private async void btnReadStreamFile_Click(object sender, RoutedEventArgs e) { StorageFile sf = await storageFolder.GetFileAsync(this.tbFileName.Text.Trim()); using (IRandomAccessStream readStream = await sf.OpenAsync(FileAccessMode.Read)) { using (DataReader dataReader = new DataReader(readStream)) { UInt size = readStream.Size; if (size <= UInt.MaxValue) { UInt numBytesLoaded = await dataReader.LoadAsync((UInt)size); string filecontent = dataReader.ReadString(numBytesLoaded); tb_show.Text = "提示:文件以Stream方式读取成功,读取的内容为-“" + filecontent + "”"; } } } } }  如需源码请点击 Win8File_gimoonet.rar 下载。VS+Windows8开发。

Windows 8技巧:windows 8文件 文件夹管理[文件以及文件夹操作] 在本文中我们将学习win8中的文件以及文件夹的各种操作。在本文中文件操作主要是讲述:删除文件/移动文件/复制文件/重命名文件文件夹操作分为:读

win8中文版电脑升级教程(图文) 现在去电子商场你会发现很多品牌机都已经预装了最新的Win8操作系统。在中国,市面上大多数OEM品牌机新机预装的都是Windows8中文版操作系统。查看计

win8启动后自动进入传统桌面(避开Metro)设置教程 对于预览版的Windows8系统,每天启动电脑后的第一件事就是从Metro开始屏幕上点击桌面回到传统界面,久而久之,就感觉十分麻烦。虽然Metro开始屏幕给

标签: 关闭windows怎么关

本文链接地址:https://www.jiuchutong.com/biancheng/363785.html 转载请保留说明!

上一篇:Windows 8技巧:Windows 8 中的Toast Tile Badge通知的使用方法 (windows 8)

下一篇:Windows 8技巧:windows 8文件 文件夹管理[文件以及文件夹操作] (windows8使用技巧)

  • 材料暂估可以跨年度吗
  • 营改增后土地增值税应税收入的确认
  • 企业裁员补偿金标准是多少
  • 分期付款购买商品的会计分录
  • 会计发票怎么样粘贴,记账凭证也要粘上吗
  • 自来水公司代收污水处理费账务处理
  • 小企业固定资产折旧方法
  • 城镇土地使用税的计税依据
  • 我国进口货物交税如何计算? 
  • 营改增之后餐饮业的税收政策
  • 未缴纳个人所得税承诺书模板
  • 公司进货可以计提折旧吗
  • 发票金额开错说明如何书写?
  • 贷款合同个人有吗
  • 工会有纳税号吗
  • 个体户可以不领税控盘吗
  • 个体定税标准
  • 非同一控制企业合并商誉
  • 制造费用明细科目大全
  • 抵扣联和发票联算一张发票吗
  • 培训学校的收入
  • 客户退回货物会计分录
  • php获取文件扩展内容
  • 建筑工程增值税税率是多少
  • php中提交表单数据
  • 默认网关为什么有两个
  • h5适配iphonex
  • phpstan
  • Vite + Vue3 +Vant4构建项目时,按需引入使用Toast组件,引用 showToast 时出现编译报错的解决方案
  • php操作步骤
  • php操作json
  • php序列化和反序列化函数
  • php接口验证
  • 前端生成docx
  • 小规模纳税人采购零配件税率
  • 公司帐户到银行怎么取钱
  • 外商独资企业资本金要求
  • 生产企业成本会计做账流程
  • 负数红字发票如何申报
  • 土地增值税清算的条件
  • 印花税的计税依据为各种应税凭证上所记载的计税金额
  • 子公司和分公司的区别
  • 现金折扣的账务处理最新
  • 住房租金专项附加扣除
  • 往来账款应该怎么记账
  • 装修费用是当月支付吗
  • 垃圾清运费的收费标准乱要钱怎么办
  • 跨年的管理费用可以直接冲吗
  • 公司注销财务账本怎么处理
  • 生产型企业成品入库会计分录
  • 企业会计制度设计论文题目
  • 领导出差差旅费怎么报销
  • linux下apache、mysql、php安装配置详细笔记
  • u盘怎么装win7系统步骤
  • win2003peiso
  • ubuntu系统怎样
  • centos7如何修改用户名
  • 操作系统运行慢怎么解决
  • centos安装图形oracle11g
  • xp系统1
  • 打开本地搜索
  • xp系统的设置在哪里
  • linux的三个部分
  • rdclient怎么用win10怎么设置
  • win8如何打开任务管理器
  • surface pro7应用
  • Win8系统32位和64位哪个好应该如何选择
  • 微软认为
  • cocos2d rpg
  • 虚拟内存系统盘
  • Lesson01_01 HTML基础
  • unity2d图片调后一层
  • unity简单小游戏案例
  • js简单实现鼠标移动后面文字也移动
  • android资源文件
  • jquery删除table行
  • 河南省出租车网
  • 华为领导班子成员名单
  • 宁波税务局qzzn
  • 十堰市税务大厅
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设