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

AppendLinesAsync() public static method

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

Same methods

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

Usage Example

示例#1
0
文件: FileIO.cs 项目: baskren/Pontoon
        /// <summary>
        /// Appends lines of text to the specified file using the specified character encoding.
        /// </summary>
        /// <param name="file">The file that the lines are appended 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 AppendLinesAsync(IStorageFile file, IEnumerable <string> lines, UnicodeEncoding encoding)
        {
#if __ANDROID__ || __UNIFIED__ || WIN32 || TIZEN
            return(PathIO.AppendLinesAsync(file.Path, lines, encoding));
#elif WINDOWS_UWP || WINDOWS_APP || WINDOWS_PHONE_APP || WINDOWS_PHONE_81
            return(Windows.Storage.FileIO.AppendLinesAsync((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();
                s.Position = s.Length;

                using (StreamWriter sw = new StreamWriter(s, UnicodeEncodingHelper.EncodingFromUnicodeEncoding(encoding)))
                {
                    foreach (string line in lines)
                    {
                        sw.WriteLine(line);
                    }
                }
            }));
#else
            throw new PlatformNotSupportedException();
#endif
        }