gpt4 book ai didi

windows-phone-7 - IsolatedStorageFileStream 上不允许的操作

转载 作者:行者123 更新时间:2023-12-04 07:19:19 26 4
gpt4 key购买 nike

创建后打开文件时出现错误

using (var myFileStore = IsolatedStorageFile.GetUserStoreForApplication())
{
myFileStore.CreateFile(DateTime.Now.Ticks + ".txt");
}
using (var myFileStore = IsolatedStorageFile.GetUserStoreForApplication())
{
temp = myFileStore.GetFileNames();
for (int k = 0; k < temp.Length; k++)
{
IsolatedStorageFileStream file1 = myFileStore.OpenFile(temp[k], FileMode.Open, FileAccess.Read);
dataSource.Add(new SampleData() { Name = temp[k], Size = Convert.ToString(Math.Round(Convert.ToDouble(file1.Length) / 1024 / 1024, 1) + " MB") });
}
}

最佳答案

那是因为您没有关闭 CreateFile 方法返回的流!

您的代码应如下所示:

using (var myFileStore = IsolatedStorageFile.GetUserStoreForApplication())
{
myFileStore.CreateFile(DateTime.Now.Ticks + ".txt").Dispose();
}

using (var myFileStore = IsolatedStorageFile.GetUserStoreForApplication())
{
using(myFileStore.CreateFile(DateTime.Now.Ticks + ".txt"))
{
}
}

在下面的 OpenFile 中也是如此。

最重要的是,您应该始终 处理您的流(通过使用 using 子句或 Dispose() 方法)

关于windows-phone-7 - IsolatedStorageFileStream 上不允许的操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12584813/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com