我正在使用 XmlSerializer,每次将一个项目添加到我的列表中时,我都会调用 save 方法:
async public void save(List<string> eingabe)
{
var serializer = new XmlSerializer(typeof(List<string>));
StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
StorageFile sampleFile =
await storageFolder.CreateFileAsync(speicherPfad, CreationCollisionOption.ReplaceExisting);
var file = await sampleFile.OpenAsync(FileAccessMode.ReadWrite);
serializer.Serialize(file.AsStreamForWrite(), eingabe);
file.Dispose();
}
当应用程序启动时,我调用加载方法:
public async Task<List<string>> load()
{
List<string> ausgabe = new List<string>();
XmlSerializer serializer = new XmlSerializer(typeof(List<string>));
StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
StorageFile sampleFile = await storageFolder.CreateFileAsync(speicherPfad, CreationCollisionOption.ReplaceExisting);
var file = await sampleFile.OpenAsync(FileAccessMode.Read);
List<string> speicher = (List<string>)serializer.Deserialize(file.AsStreamForRead());
file.Dispose();
return speicher;
}
问题:在加载方法中,文件总是空的(大小= 0),我不知道为什么