位置: 编程技术 - 正文

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使用技巧)

  • 个人所得税手续费返还时间
  • 财务软件应交增值税明细科目
  • 增值税普通发票税率
  • 公司名下的车怎么报废
  • 补缴以前年度附加税
  • 空调可以直接做费用吗
  • 固定资产清理期末余额在借方是什么意思
  • 公司税务状态变更怎么办
  • 发出商品的会计核算
  • 如何计算个别资金成本?
  • 小规模纳税人购置税控设备
  • 筹办期的工资费用是什么
  • 车贷抵押金计入会计科目?
  • 是否退还投标文件
  • 稳定性流动资产是经营性流动资产吗
  • 制造业异地安装要预缴增值税吗?如何预缴?
  • 税收滞纳金和税金滞纳金有什么区别
  • 利税总额含企业所得税吗
  • 生物性资产是什么
  • 季度不超30万需计提增值税吗
  • 记账凭证领用材料如何填写
  • 多计提的冲回如何记账?
  • 购进商品用于样品赠送的账务处理
  • 上年度多计提的工资怎么冲减
  • 没有销项税进项要交税吗
  • 一般商业企业要缴纳哪些税?
  • win11 zen1
  • 管理员已阻止你运行此应用 win10
  • 经济成本和会计成本的大小
  • 其他应收账款怎么算
  • 物流公司的收入怎么记账
  • 银行存款总账怎么登记图片
  • 触屏不灵敏怎么调整oppo
  • laravel自带队列效率
  • 委托收款拒收会退回吗
  • uni-app实战教程
  • 自然人税收管理系统扣缴客户端app
  • 异地工程款预缴
  • css过渡动画属性
  • 公允价值变动损益会计处理
  • 小微企业的所得税税率是多少
  • 处置固定资产账务处理进什么科目
  • 企业收到土地补偿金需要开发票吗
  • 假退库会计分录
  • SQL Server 2008 R2 超详细安装图文教程
  • SQL Server 2008中SQL之WaitFor使用介绍
  • 辅助账簿属于会计档案吗
  • 行政事业单位工作时间
  • 保险理赔进项税额转出
  • 志愿者服务活动有哪些内容
  • 怎么冲减多计提的工会经费
  • 企业为什么要转移用工风险什么意思
  • 增值税留抵税额借贷方向
  • 职工福利费无发放原因
  • 汇算清缴主要检查什么
  • 未使用的固定资产计提折旧应当计入
  • 企业的经济补偿包括哪些
  • 小规模纳税人可以抵税吗
  • 管理费用是负数影响利润表吗
  • 成本收入率和收入成本率的区别
  • mysql 随机io
  • Windows7/2008中批量删除隧道适配器的方法
  • windows无法启动wlanautoconfig服务
  • wind2003
  • ubuntu怎么安装程序
  • win7系统换桌面
  • ubuntu virtual box
  • 如何解决焦虑的心理
  • win10重启更新的时候强制关机后会发生啥
  • android开发程序
  • javascript函数的定义
  • jquery中有哪些dom操作?
  • unity与android交互详细
  • python数据类型详细介绍
  • jquery的form方法
  • 反编译android动态库
  • 我国历年财政支出总额
  • 打单子的打印机能否打a4的纸
  • 税务稽查立案标准金额
  • 河北公示信息网
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设