using System; using System.Text; using System.Threading.Tasks; using System.Windows; using Windows.Storage; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.InteropServices.WindowsRuntime; using Windows.Foundation; using Windows.Foundation.Collections; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Controls.Primitives; using Windows.UI.Xaml.Data; using Windows.UI.Xaml.Input; using Windows.UI.Xaml.Media; using Windows.UI.Xaml.Navigation; // 空白ページの項目テンプレートについては、https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x411 を参照してください namespace App2 { /// /// それ自体で使用できる空白ページまたはフレーム内に移動できる空白ページ。 /// public sealed partial class MainPage : Page { public MainPage() { this.InitializeComponent(); } private const string OutFile = @"sample.txt"; private async void SaveFile_Click(object sender, RoutedEventArgs e) { SaveFile.IsEnabled = false; await AddTextToFile(); SaveFile.IsEnabled = true; SaveFile.Content = "Created!!"; } public async Task AddTextToFile() { StorageFolder folder = Windows.Storage.ApplicationData.Current.LocalFolder; StorageFile samplefile = await folder.CreateFileAsync(OutFile, CreationCollisionOption.ReplaceExisting); string text = @"Line 01 Line 02 "; await FileIO.WriteTextAsync(samplefile, text); await FileIO.AppendTextAsync(samplefile, text); var lines = await FileIO.ReadLinesAsync(samplefile); foreach (var l in lines) System.Diagnostics.Debug.WriteLine(l); await FileIO.WriteTextAsync(samplefile, text); var lines2 = await FileIO.ReadLinesAsync(samplefile); foreach (var l in lines2) System.Diagnostics.Debug.WriteLine(l); } } }