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

WriteLinesAsync() public static method

Writes lines of text to the file at the specified path or URI.
public static WriteLinesAsync ( string absolutePath, IEnumerable lines ) : System.Threading.Tasks.Task
absolutePath string The path of the file that the lines are written to.
lines IEnumerable The list of text strings to append as lines.
return System.Threading.Tasks.Task
        public static Task WriteLinesAsync(string absolutePath, IEnumerable<string> lines)
        {
            return WriteLinesAsync(absolutePath, lines, UnicodeEncoding.Utf8);
        }

Same methods

PathIO::WriteLinesAsync ( string absolutePath, IEnumerable lines, UnicodeEncoding encoding ) : System.Threading.Tasks.Task

Usage Example

示例#1
0
文件: FileIO.cs 项目: baskren/Pontoon
        /// <summary>
        /// Writes lines of text to the specified file using the specified character encoding.
        /// </summary>
        /// <param name="file">The file that the lines are written to.</param>
        /// <param name="lines">The list of text strings to append as lines.</param>
        /// <param name="encoding">The character encoding of the file.</param>
        /// <returns>No object or value is returned when this method completes.</returns>
        public static Task WriteLinesAsync(IStorageFile file, IEnumerable <string> lines, UnicodeEncoding encoding)
        {
#if __ANDROID__ || __UNIFIED__ || WIN32 || TIZEN
            return(PathIO.WriteLinesAsync(file.Path, lines, encoding));
#elif WINDOWS_UWP || WINDOWS_APP || WINDOWS_PHONE_APP || WINDOWS_PHONE_81
            return(Windows.Storage.FileIO.WriteLinesAsync((Windows.Storage.StorageFile)((StorageFile)file), lines, (Windows.Storage.Streams.UnicodeEncoding)((int)encoding)).AsTask());
#elif WINDOWS_PHONE
            return(Task.Run(async() =>
            {
                Stream s = await file.OpenStreamForWriteAsync();
                using (StreamWriter sw = new StreamWriter(s, UnicodeEncodingHelper.EncodingFromUnicodeEncoding(encoding)))
                {
                    foreach (string line in lines)
                    {
                        sw.WriteLine(line);
                    }
                }
            }));
#else
            throw new PlatformNotSupportedException();
#endif
        }