在 Windows Phone 上的 C# 中尝试访问该方法失败: System.IO.FileStream..ctor(System.String, System.IO.FileMode) [英] In C# on windows phone Attempt to access the method failed: System.IO.FileStream..ctor(System.String, System.IO.FileMode)
问题描述
FileStream FS = new FileStream("MyFolder\\MyFile.txt", FileMode.Open);
IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();
StreamWriter writeFile = new StreamWriter(new IsolatedStorageFileStream("MyFolder\\MyFile.txt", FileMode.Append, myIsolatedStorage));
using (writeFile)
{
FS.Seek(0, SeekOrigin.End);
writeFile.WriteLine(txtWrite.Text);
writeFile.Close();
System.Diagnostics.Debug.WriteLine("Now I am here");
}
当我尝试运行此代码(尝试将数据附加到现有文本文件中)时,出现异常
When I am trying to run this code(trying to append data into an existing text file), getting exception
"尝试访问该方法失败:System.IO.FileStream..ctor(System.String, System.IO.FileMode)"
"Attempt to access the method failed: System.IO.FileStream..ctor(System.String, System.IO.FileMode)"
我在这里犯了什么错误?
What is the mistake I have done here?
推荐答案
我终于在挣扎了 4 小时后成功了:
Finally I made it working after struggling for 4 hrs:
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");
我删除了文件流方法并做了一些修改.它开始工作.感谢所有试图帮助我提出建议的人
I removed the file stream method and did some modifications. Its started to work. Thanks to everybody who tried to help me with your suggestions
这篇关于在 Windows Phone 上的 C# 中尝试访问该方法失败: System.IO.FileStream..ctor(System.String, System.IO.FileMode)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!