IBuffer^ Scenario3::GetBufferFromString(String^ str) { InMemoryRandomAccessStream^ memoryStream = ref new InMemoryRandomAccessStream(); DataWriter^ dataWriter = ref new DataWriter(memoryStream); dataWriter->WriteString(str); return dataWriter->DetachBuffer(); } void Scenario3::ReadBytesButton_Click(Object^ sender, RoutedEventArgs^ e) { StorageFile^ file = rootPage->SampleFile; if (file != nullptr) { create_task(FileIO::ReadBufferAsync(file)).then([this, file](IBuffer^ buffer) { 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; }); } }
转载于:https://www.cnblogs.com/deagle/articles/2576531.html