您的位置:首页 > 其它

windows phone 8 异步访问独立存储区

2014-09-11 15:19 330 查看
StorageFile storageFile = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(new Uri("msappdata:///local/CaptainsLog.store "));
Stream readStream = await StorageFile.OpenStreamForReadAsync();
using (StreamReader reader = new StreamReader(readStream))
{
theData = await reader.ReadToEndAsync();
}


public static async Task SaveLogFile(string logData)
{
Debug.WriteLine(logData);
try
{

logFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync(SysLog.LOGFOLDERNAME, CreationCollisionOption.OpenIfExists);
string logFileName = GenerateLogFileName();
logFile = await logFolder.CreateFileAsync(logFileName, CreationCollisionOption.OpenIfExists);
}
using (IRandomAccessStream outStream = await logFile.OpenAsync(FileAccessMode.ReadWrite))
{
Stream s = outStream.AsStreamForWrite();
s.Seek(0, SeekOrigin.End);
byte[] readBuffer = Encoding.UTF8.GetBytes(logData + "\r\n");
await s.WriteAsync(readBuffer, 0, readBuffer.Length);
await s.FlushAsync();
}
}
catch (Exception ex)
{
Log("SaveLogFile Error", ex.Message);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: