日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2025/3/8 编程问答 15 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的win8学习--------File的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。