创建文件后打开该文件时出现错误
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
method!
您的代码应如下所示:
using (var myFileStore = IsolatedStorageFile.GetUserStoreForApplication())
{
myFileStore.CreateFile(DateTime.Now.Ticks + ".txt").Dispose();
}
or
using (var myFileStore = IsolatedStorageFile.GetUserStoreForApplication())
{
using(myFileStore.CreateFile(DateTime.Now.Ticks + ".txt"))
{
}
}
下面的 OpenFile 也是如此。
底线你应该always处置您的流(通过使用using
条款或Dispose()
method)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)