我尝试将数据保存到文件,但是收到以下错误Operation not permitted on IsolatedStorageFileStream
行中的IsolatedStorageFileStream fileStream = new IsolatedStorageFileStream(path, FileMode.OpenOrCreate, storage);
public SaveFile(string path,string data)
{
var storage = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream fileStream = new IsolatedStorageFileStream(path, FileMode.OpenOrCreate, storage);
StreamWriter writer = new StreamWriter(fileStream);
writer.Write(data);
}
最佳答案
试试这个:
public void SaveFile(string path, string data)
{
using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
{
using (var fileStream = new IsolatedStorageFileStream(path + fileName, FileMode.Create, FileAccess.Write, storage))
{
using (StreamWriter writer = new StreamWriter(fileStream))
{
writer.WriteLine(data);
writer.Close();
}
fileStream.Close();
}
}
}