win8学习--------File

//创建文件
using namespace Windows::Storage; 
MainPage^ rootPage;rootPage = MainPage::Current;
create_task(KnownFolders::DocumentsLibrary->CreateFileAsync(rootPage->Filename, CreationCollisionOption::ReplaceExisting)).then([this](StorageFile^ file){rootPage->SampleFile = file;OutputTextBlock->Text = "The file '" + file->Name + "' was created.";});

static property Platform::String^ Filename
{
Platform::String^ get()
{
return ref new Platform::String(L"sample.dat");
}
}

 

property Windows::Storage::StorageFile^ SampleFile
{
Windows::Storage::StorageFile^ get()
{
return sampleFile;
}
void set(Windows::Storage::StorageFile^ value)
{
sampleFile = value;
}
}

 
2、向文件中写入信息----写Text内容
//另加空间名using namespace concurrency; StorageFile
^ file = rootPage->SampleFile;//刚才创建的文件if (file != nullptr){String^ userContent = InputTextBox->Text;if (userContent != nullptr && !userContent->IsEmpty()){create_task(FileIO::WriteTextAsync(file, userContent)).then([this, file, userContent](task<void> task){try{task.get();OutputTextBlock->Text = "The following text was written to '" + file->Name + "':\n\n" + userContent;}catch(COMException^ ex){rootPage->HandleFileNotFoundException(ex);}});}else{OutputTextBlock->Text = "The text box is empty, please write something and then click 'Write' again.";}}
//读文件内容-----读text内容
 rootPage->ResetScenarioOutput(OutputTextBlock);StorageFile^ file = rootPage->SampleFile;if (file != nullptr){String^ userContent = InputTextBox->Text;if (userContent != nullptr && !userContent->IsEmpty()){IBuffer^ buffer = GetBufferFromString(userContent);create_task(FileIO::WriteBufferAsync(file, buffer)).then([this, file, buffer, userContent](task<void> task){try{task.get();OutputTextBlock->Text = "The following " + buffer->Length.ToString() + " bytes of text were written to '" + file->Name + "':\n\n" + userContent;}catch(COMException^ ex){rootPage->HandleFileNotFoundException(ex);}});}else{OutputTextBlock->Text = "The text box is empty, please write something and then click 'Write' again.";}}

 

//写Byte流
using namespace Windows::Storage::Streams;rootPage->ResetScenarioOutput(OutputTextBlock);StorageFile^ file = rootPage->SampleFile;if (file != nullptr){String^ userContent = InputTextBox->Text;if (userContent != nullptr && !userContent->IsEmpty()){create_task(file->OpenTransactedWriteAsync()).then([this, file, userContent](task<StorageStreamTransaction^> task){try{StorageStreamTransaction^ transaction = task.get();DataWriter^ dataWriter = ref new DataWriter(transaction->Stream);dataWriter->WriteString(userContent);create_task(dataWriter->StoreAsync()).then([this, file, dataWriter, transaction, userContent](unsigned int bytesWritten){transaction->Stream->Size = bytesWritten; // reset stream size to override the filecreate_task(transaction->CommitAsync()).then([this, file, userContent](){OutputTextBlock->Text = "The following text was written to '" + file->Name + "' using a stream:\n\n" + userContent;});});}catch(COMException^ ex){rootPage->HandleFileNotFoundException(ex);}});}else{OutputTextBlock->Text = "The text box is empty, please write something and then click 'Write' again.";}}
//读byte流

rootPage->ResetScenarioOutput(OutputTextBlock);
StorageFile^ file = rootPage->SampleFile;
if (file != nullptr)
{
create_task(FileIO::ReadBufferAsync(file)).then([this, file](task<IBuffer^> task)
{
try
{
IBuffer^ buffer = task.get();
DataReader^ dataReader = DataReader::FromBuffer(buffer);
String^ fileContent = dataReader->ReadString(buffer->Length);
OutputTextBlock->Text = "The following " + buffer->Length.ToString() + " bytes of text were read from '" + file->Name + "':\n\n" + fileContent;
}
catch(COMException^ ex)
{
rootPage->HandleFileNotFoundException(ex);
}
});
}

转载于:https://www.cnblogs.com/win-and-first/archive/2012/08/21/win8.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/548340.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

centos下升级g++版本

转载请注明文章出处&#xff1a;https://juejin.im/post/5d0ef5376fb9a07ef63fe74e CentOS 7官方源带的gcc最新版本是4.8.5&#xff0c;发布于2015年&#xff0c;年代久远且不支持c14。要编译c14及以上项目&#xff0c;必须要升级现有版本或者安装高版本的gcc。&#xff08;yu…

HDOJ---2546 饭卡[DP01背包问题]

饭卡 Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4160 Accepted Submission(s): 1410 Problem Description电子科大本部食堂的饭卡有一种很诡异的设计&#xff0c;即在购买之前判断余额。如果购买一个商品之…

c++守护进程

#include #include <boost/process.hpp> #include int main(int argc, char* argv[]) { //此进程一定要防止多开 std::string exe_name(“C:\Users\yinpinghua\source\repos\ConsoleApplication2\x64\Debug\ConsoleApplication2.exe”); //c17语法 if (!std::filesy…

八皇后问题 递归求解法

#include <iostream> #include <fstream> #include <string.h>/** 八皇后问题递归方法实现 */ using namespace std;ofstream file;//用以计数计算结果的数目 int count 1; /** 打印的棋盘其中打印1的位置是皇后的位置&#xff0c;0空位。 这里因为在控制台…

Hadoop入门-单机伪分布式配置

为了配置的的方便建议先提升你的登录用户权限&#xff0c;本配置中凡是要在终端中输入的命令都用红色字体&#xff0c;需注意对应的目录用了色字体标出。 启用超级用户 sudo passwd root&#xff08;然后输入你的超级用户密码&#xff09;以后在终端中输入su&#xff0c;再输入…

nginx 监听同一端口

#user nobody; worker_processes 1; //主从进程 #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-st…

squid代理服务器在企业网中的应用

一&#xff0c;squid服务器概述 Squid是一种在Linux系统下使用的优秀的代理服务器软件。 squid不仅可用在Linux系统上&#xff0c;还可以用在AIX、Digital Unix、FreeBSD、HP-UX、Irix、NetBSD、Nextstep、SCO和Solaris等系统上。 Squid与Linux下其它的代理软件如Apache、Socks…

判断linux进程是否存在

#include #include #include int main() { FILE* fp; std::string buffer; fp popen(“ps -ef|grep 进程名| grep -v grep |wc -l”, “r”); //1&#xff1a;存在 &#xff1a;不存在 fread(&buffer[0], 1,1, fp); std::cout << buffer << std::endl; pclo…

MPLS ×××配置

MPLS 配置以下面拓扑为例配置MPLS 拓扑说明&#xff1a;R1&#xff0c;R2、R3路由器上分别配置Loopback1 接口&#xff0c;IP地址分别为1.1.1.1&#xff0c;2.2.2.2 3.3.3.3&#xff1b;并配置OSPF&#xff0c;让MPLS区域内的地址可以进行标签交换1、在MPLS区域配置标签交换R1&…

future promise shared_future简单使用

#include #include #include /furture 和promi******************/ int display(const int& value) { return 10 value; } //不能传引用&#xff0c;是简单的值拷贝 int display1(std::shared_future f) { //地方会一直等待&#xff0c;阻塞状态,由其它线程传入值 int…

Linux CentOS 查看服务器信息命令及其它常用命令

一&#xff1a;使用CentOS常用命令查看cpu more /proc/cpuinfo | grep “model name”grep “model name” /proc/cpuinfo[rootlocalhost /]# grep “CPU” /proc/cpuinfomodel name : Intel(R) Pentium(R) Dual CPU E2180 2.00GHzmodel name : Intel(R) Pentium(R) Dual CPU …

linux下使用c++17编译filesystem

#ifdef _WIN32 #include namespace fs std::filesystem; #else #include <experimental/filesystem> namespace fs std::experimental::filesystem; #endif #include int main() { auto path fs::path(“root/test.txt”); //后面会追加 fs::resize_file(path, 1024…

交叉编译脚本命令

::只显示echo echo off ::设置DOS环境的字体颜色 color 06 ::设置GOPATH路径和golandIDE相同 SET projectNameapetboss SET projectPathF:\project\h5gamesvr SET GOPATH%projectPath% ;SET CGO_ENABLED0 ;SET GOOSlinux ;SET GOARCHamd64 ;go build -v -o build/%projectNam…

oracle异常处理

2019独角兽企业重金招聘Python工程师标准>>> CREATE OR REPLACE PACKAGE BODY TEST_PACKAGE IS --异常分为&#xff1a;编译是错误(语法错误)、运行时错误(编译器无法检查&#xff0c;对应某些情况程序是可以正常执行的&#xff0c;但在某些特点情况下程序不会正确执…

Linux下调tcp最大参数

TCP并发请求溺出 调优&#xff1a;系统开启某个监听端口后&#xff0c;当多个TCP请求连接监听端后&#xff0c;会把多个请求交给backlog的默认监听队列由socket server一并处理&#xff0c;backlog有自己的队列长度默认128&#xff0c;当机器处理能力较慢且并发请求值较高时就要…

IOS程序内发短信

2019独角兽企业重金招聘Python工程师标准>>> iOS4.0新加入了MFMessageComposeViewController和MFMessageComposeViewControllerDelegate,提供了发送短信的接口,可以像发送邮件那样不用跳出程序来发送短信. 介绍可参阅Message UIFramework Reference 一些笔记: MFMes…

遍历tuple

#include #include namespace detail { template<class Tuple, class F, std::size_t…Is> void for_each(Tuple&& tuple, F&& f, std::index_sequence<Is…>) { using expand int[]; void(expand{ 0, (f(std::get(std::forward(tuple))), 0)……

JQUERY学习第二天之制作横纵向导航菜单

$(document).ready(function(){ //页面中的DOM已经装载完成时&#xff0c;执行的代码 $(".main > a").click(function(){ //找到主菜单项对应的子菜单项 var ulNode $(this).next("ul"); /* if (ulNode.css("display") "none"…

可变参数模板展开

//#include //#include //#include //#include //#include <type_traits> //#include void printer() { } template void printer(T a) { std::cout << a << std::endl; } //c11 template<class …Args> void printer(Args&&… args) …

增强决策能力

(1)克服从众心理。从众心理是指个体对社会的认识和态度常常受到群体对社会的认识和态度的左右。从众行为者的意识深处考虑的是自己的行为能否为大众所接受&#xff0c;追寻的是一种安全感。从众行为者认为群体的规范、他人的行为是正确的时候&#xff0c;就会表现出遵从&#x…