How to read file (Metro/WinRT)

前端 未结 4 1799
再見小時候
再見小時候 2021-01-04 03:09

I\'m quite astounded by the apparent complexity of this seemingly simple task. I know that I have to use the StorageFile class, and I\'ve found this example, bu

相关标签:
4条回答
  • 2021-01-04 03:34

    This web page might be helpful: http://blog.jerrynixon.com/2012/06/windows-8-how-to-read-files-in-winrt.html

    Relevant code:

    public string CurrentFileBuffer
    {
        get; private set;
    }
    
    public async void ReadTextFile(string Path)
    {
        var folder = Package.Current.InstalledLocation;
        var file = await folder.GetFileAsync(Path);
        var read = await FileIO.ReadTextAsync(file);
        CurrentFileBuffer = read;
    }
    
    0 讨论(0)
  • 2021-01-04 03:44

    You can use the FileIO class like so.

    public async void Read(IStorageFile file)
    {
        var lines = await FileIO.ReadLinesAsync(file);
    
    }
    
    0 讨论(0)
  • 2021-01-04 03:45

    Windows.Storage.FileIO has a bunch of helper/utility methods that do the job in a single line of code rather than using StorageIO interfaces and classes.

    e.g.

    ReadLineAsync()
    ReadTextAsync()
    WriteLineAsync()
    WriteTextAsync()
    
    0 讨论(0)
  • 2021-01-04 03:48

    You can get your file by using this:

    StorageFile file3 = await StorageFile.GetFileFromPathAsync(@"C:\myFile.txt");
    
    0 讨论(0)
提交回复
热议问题