InTheHand.Storage.PathIO.ReadTextAsync C# (CSharp) Method

ReadTextAsync() public static method

Reads the contents of the file at the specified path or URI and returns text.
public static ReadTextAsync ( string absolutePath ) : Task
absolutePath string The path of the file to read.
return Task
        public static Task<string> ReadTextAsync(string absolutePath)
        {
            return ReadTextAsync(absolutePath, UnicodeEncoding.Utf8);
        }

Same methods

PathIO::ReadTextAsync ( string absolutePath, UnicodeEncoding encoding ) : Task

Usage Example

示例#1
0
文件: FileIO.cs 项目: baskren/Pontoon
        /// <summary>
        /// Reads the contents of the specified file using the specified character encoding and returns text.
        /// </summary>
        /// <param name="file">The file to read.</param>
        /// <param name="encoding">The character encoding of the file.</param>
        /// <returns>When this method completes successfully, it returns the contents of the file as a text string.</returns>
        public static Task <string> ReadTextAsync(IStorageFile file, UnicodeEncoding encoding)
        {
#if __ANDROID__ || __UNIFIED__ || WIN32 || TIZEN
            return(PathIO.ReadTextAsync(file.Path, encoding));
#elif WINDOWS_UWP || WINDOWS_APP || WINDOWS_PHONE_APP || WINDOWS_PHONE_81
            return(Windows.Storage.FileIO.ReadTextAsync((Windows.Storage.StorageFile)((StorageFile)file), (Windows.Storage.Streams.UnicodeEncoding)((int)encoding)).AsTask());
#elif WINDOWS_PHONE
            return(Task.Run <string>(async() =>
            {
                Stream s = await((StorageFile)file).OpenStreamForReadAsync();
                using (StreamReader sr = new StreamReader(s, UnicodeEncodingHelper.EncodingFromUnicodeEncoding(encoding)))
                    return await sr.ReadToEndAsync();
            }));
#else
            throw new PlatformNotSupportedException();
#endif
        }