我在独立文件存储方面遇到了一些问题,我正在尝试将其追加到一个文件中,但是当我使用下面的代码时,我得到了关于此行上无效参数的错误
IsolatedStorageFileStream("Folder\\barcodeinfo.txt", FileMode.Append,
FileMode.OpenOrCreate, myStore))我想这和Filemode.Append有关..我正在尝试附加到文件中,而不是创建新的
// Obtain the virtual store for the application.
IsolatedStorageFile myStore = IsolatedStorageFile.GetUserStoreForApplication();
// Create a new folder and call it "MyFolder".
myStore.CreateDirectory("Folder");
// Specify the file path and options.
using (var isoFileStream = new IsolatedStorageFileStream("Folder\\barcodeinfo.txt", FileMode.Append, FileMode.OpenOrCreate, myStore))
{
//Write the data
using (var isoFileWriter = new StreamWriter(isoFileStream))
{
isoFileWriter.WriteLine(textBox1.Text);
isoFileWriter.WriteLine(textBox2.Text);
isoFileWriter.WriteLine(textBox3.Text);
}
}发布于 2012-01-11 08:44:04
不存在需要两个FileModes的重载。它应该是
IsolatedStorageFileStream("Folder\\barcodeinfo.txt", FileMode.Append,
FileAccess.Write, myStore));关于FileMode.Append需要注意的重要一点是:
如果文件存在,
FileMode.Append将打开该文件并查找到文件的末尾,或者创建一个新文件。Append只能与Write一起使用。尝试查找到文件末尾之前的位置将抛出IOException,任何读取尝试都会失败并抛出NotSupportedException。
这就是使用FileAccess.Write的原因。
发布于 2012-01-11 08:42:59
看起来你有FileMode.Append, FileMode.OpenOrCreate。这是两种文件模式。第一个参数是FileMode,第二个参数应该是FileAccess。
这应该会解决你的问题。
https://stackoverflow.com/questions/8812608
复制相似问题