File system: Text read/write, binary read/write, stream read/write, recent access list and future access list
Introduced
Re-imagine the Windows 8 Store Apps File system
Demonstrates how to read and write text data
Demonstrates how to read and write binary data
Demonstrates how to read and write streaming data
Shows how to read and write "Recent access lists" and "Future access lists"
Example
1. Demonstrates how to read and write text data
Filesystem/readwritetext.xaml.cs
* * Demonstrates how to read and write text data * Note: If you need to read and write a file with an extension, you need to add a "File type association" declaration in Package.appxmanifest and make the appropriate configuration * * Storagefolder-folder Operation class * Get folder-related properties, renaming, Create ..., getting ... * * * storagefile-File Operation class * Get file-related properties, rename, Create ..., take ..., Copy ..., move ..., Delete ..., Open ..., Replace ... * FileIO-Help class * Writetextasync () for read-write Istoragefile objects-writes the specified text data to the specified file * Appendtextasync ()-Converts the specified This data is appended to the specified file * Writelinesasync ()-writes the specified multiline text data to the specified file * Appendlinesasync ()-appends the specified multiline text data to the specified file * Readtextas Ync ()-Gets the text data in the specified file * Readlinesasync ()-Gets the text data in the specified file and returns a row of data * Note: The related classes in WinRT about the storage operations are in Windows.storag
Within the E namespace */using System;
Using Windows.storage;
Using Windows.UI.Xaml;
Using Windows.UI.Xaml.Controls;
Namespace Xamldemo.filesystem {public sealed partial class Readwritetext:page {public Readwritetext () {this.
InitializeComponent (); Private async void Btnwritetext_click_1 (object sender, RoutedeventarGS e) {//create the specified file in the specified directory Storagefolder storagefolder = knownfolders.documentslibrary; Storagefile Storagefile = await Storagefolder.createfileasync ("WebabcdText.txt", Creationcollisionoption.replace
Existing);
Writes the specified text string textcontent = "I am WEBABCD" in the specified file;
Await Fileio.writetextasync (Storagefile, textcontent, Windows.Storage.Streams.UnicodeEncoding.Utf8);
Lblmsg.text = "Write success"; Private async void Btnreadtext_click_1 (object sender, RoutedEventArgs e) {//fetch in specified directory
The specified file Storagefolder storagefolder = knownfolders.documentslibrary;
Storagefile Storagefile = await Storagefolder.getfileasync ("WebabcdText.txt"); if (storagefile!= null) {//Get the text content in the specified file string textcontent = await FileIO. Readtextasync (Storagefile, Windows.Storage.Streams.UnicodeEncoding.Utf8);
Lblmsg.text = "Read result:" + textcontent; }
}
}
}
2. Demonstrates how to read and write binary data
Filesystem/readwritebinary.xaml.cs
* * Demonstrates how to read and write binary data * Note: If you need to read and write a file with an extension, you need to add a "File type association" declaration in Package.appxmanifest and make the appropriate configuration * * Storagefolder-folder Operation class * obtained Take folder-related properties, rename, Create ..., get ... * * * storagefile-File Operation class * Get file-related properties, rename, Create ..., take ..., Copy ..., move ..., Delete ..., Open ..., Replace ... * FileIO-Help class for reading and Writing Istoragefile objects * WRITEBUFFERASYNC ()-writes the specified binary data to the specified file * Readbufferasync ()-Gets the reference Binary data in a fixed file * * IBUFFER-WINRT byte array * Note: WinRT related classes in the storage operation are in the Windows.storage namespace/using Syste
M
Using Windows.storage;
Using Windows.Storage.Streams;
Using Windows.UI.Xaml;
Using Windows.UI.Xaml.Controls; Namespace Xamldemo.filesystem {public sealed partial class Readwritebinary:page {public Readwritebinar Y () {this.
InitializeComponent (); Private async void Btnwritebinary_click_1 (object sender, RoutedEventArgs e) {//in the specified directory The specified file is created storagefolder Storagefolder = knownfolders.documentSlibrary; Storagefile Storagefile = await Storagefolder.createfileasync ("WebabcdBinary.txt",
creationcollisionoption.replaceexisting);
Converts a string into binary data and saves to the specified file string textcontent = "I am WEBABCD";
Ibuffer buffer = Converterhelper.string2buffer (textcontent);
Await Fileio.writebufferasync (storagefile, buffer);
Lblmsg.text = "Write success"; Private async void Btnreadbinary_click_1 (object sender, RoutedEventArgs e) {//in specified directory
Gets the specified file Storagefolder storagefolder = knownfolders.documentslibrary;
Storagefile Storagefile = await Storagefolder.getfileasync ("WebabcdBinary.txt"); if (storagefile!= null) {//Gets binary data in the specified file, converts it to a string, and displays ibuffer buffer = await
Fileio.readbufferasync (Storagefile);
String textcontent = converterhelper.buffer2string (buffer); lblmsg.text = "Read result:" + textcontent; }
}
}
}