2

我在第三条语句中收到以下异常,我正在尝试读取文件,但它不允许我打开读取流。

这只是示例代码,但实际情况不同,Web 套接字正在尝试将字节写入文件,而其他进程(音乐播放器)正在尝试从同一文件中读取字节。我想实现这个场景。

      IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication();

            var writeStream = storage.OpenFile("sample.txt", 
                                                System.IO.FileMode.OpenOrCreate, 
                                                System.IO.FileAccess.Write, 
                                                System.IO.FileShare.Read);

            var readStream = storage.OpenFile("sample.txt", 
                                                System.IO.FileMode.Open, 
                                                System.IO.FileAccess.Read);

System.IO.IsolatedStorage.IsolatedStorageException 被捕获 HResult=-2146233264 消息=在 IsolatedStorageFileStream 上不允许操作。Source=mscorlib StackTrace: 在 System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, IsolatedStorageFile isf) at System.IO.IsolatedStorage.IsolatedStorageFile.OpenFile(String path, FileMode模式,FileAccess 访问)在 FileReadWriteSample.MainPage.Button_Click(Object sender, RoutedEventArgs e) InnerException:

4

2 回答 2

3

您已经为该文件打开了一个流(通过第二条语句)。您需要先处理该流,然后才能打开另一个流。

于 2013-04-26T18:36:13.240 回答
0

解决方案是也授予读取流的文件访问权限。它解决了我的问题。

http://social.msdn.microsoft.com/Forums/en-us/wpdevelop/thread/f9e55760-e533-4124-a7ed-7f8f15e00e60

于 2013-04-27T04:52:26.567 回答