Windows phone 7 在windows phone上的C#中,尝试访问方法失败:System.IO.FileStream..ctor(System.String,System.IO.FileMode)
当我尝试运行此代码(尝试将数据附加到现有文本文件中)时,出现异常 “尝试访问该方法失败: System.IO.FileStream..ctor(System.String,System.IO.FileMode)”Windows phone 7 在windows phone上的C#中,尝试访问方法失败:System.IO.FileStream..ctor(System.String,System.IO.FileMode),windows-phone-7,Windows Phone 7,当我尝试运行此代码(尝试将数据附加到现有文本文件中)时,出现异常 “尝试访问该方法失败: System.IO.FileStream..ctor(System.String,System.IO.FileMode)” 我在这里犯了什么错误?可能是您试图打开同一个文件两次吗 您的问题(带答案)的版本可在中查看。不要使用文件流类目录。通过以下方法获取您的流: 经过4个小时的努力,我终于成功了: IsolatedStorageFile myIsolatedStorage = IsolatedSt
我在这里犯了什么错误?可能是您试图打开同一个文件两次吗
您的问题(带答案)的版本可在中查看。不要使用
文件流
类目录。通过以下方法获取您的流:
经过4个小时的努力,我终于成功了:
IsolatedStorageFile myIsolatedStorage =
IsolatedStorageFile.GetUserStoreForApplication();
using (var writeFile = myIsolatedStorage.OpenFile("MyFolder\\MyFile.txt", FileMode.Append))
using (var writeFileStream = new StreamWriter(writeFile))
{
writeFileStream.WriteLine(txtWrite.Text);
System.Diagnostics.Debug.WriteLine("Now I am here");
}
我删除了文件流方法并做了一些修改。它开始起作用了。
感谢所有试图帮助我提出建议的人看来这是一个方法访问错误,而不是文件访问错误。@RichardSzalay,是的。访问此方法时出现例外情况:FS.Seek(0,SeekOrigin.End);谢谢你的回复。它可以工作,但不会将数据附加到现有的文本文件中,而是会覆盖它。@SankarGuda您必须使用FileMode.APPEND打开文件
IsolatedStorageFile myIsolatedStorage =
IsolatedStorageFile.GetUserStoreForApplication();
using (var writeFile = myIsolatedStorage.OpenFile("MyFolder\\MyFile.txt", FileMode.Append))
using (var writeFileStream = new StreamWriter(writeFile))
{
writeFileStream.WriteLine(txtWrite.Text);
System.Diagnostics.Debug.WriteLine("Now I am here");
}
IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();
StreamWriter writeFile = new StreamWriter(new IsolatedStorageFileStream("MyFolder\\MyFile.txt", FileMode.Append, myIsolatedStorage));
writeFile.Flush();
System.Diagnostics.Debug.WriteLine(txtWrite.Text);
writeFile.WriteLine(txtWrite.Text);
writeFile.Close();
System.Diagnostics.Debug.WriteLine("Now I am here");