日期:2014-05-17 浏览次数:20787 次
public async static Task Save<T>(string fileName, T data)
{
//取得当前程序存放数据的目录
StorageFolder folder = Windows.Storage.ApplicationData.Current.LocalFolder;
//创建文件,如果文件存在就覆盖
StorageFile file = await folder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);
using (Stream newFileStream = await file.OpenStreamForWriteAsync())
{
DataContractSerializer ser = new DataContractSerializer(typeof(T));
ser.WriteObject(newFileStream, data);
newFileStream.Dispose();
}
}