I am having trouble creating an IO stream.
I found the example below but for some odd reason the GetResourceStream
is not an available in the Application class. Am I missing a reference to some API?
var resource = Application.GetResourceStream(new Uri(@"/YOURASSEMBLYNAME;component/Stations.txt", UriKind.Relative));
StreamReader streamReader = new StreamReader(resource.Stream);
string x = streamReader.ReadToEnd();
If you need to read a String from your file (as I see in your example), you can use:
StorageFile textFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///YOUR FILE PATH"));
String text = await FileIO.ReadTextAsync(textFile );
You can use the methods inside the FileIO class to write to the file as well, both from a text and from a binary buffer.
If you really want to use a buffer stream, you can get it with:
IRandomAccessStream accessStream = await textFile.OpenAsync(FileAccessMode.ReadWrite);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.