Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# &引用;“流不可写”;Winform中嵌入的txt文件出现异常_C#_Winforms - Fatal编程技术网

C# &引用;“流不可写”;Winform中嵌入的txt文件出现异常

C# &引用;“流不可写”;Winform中嵌入的txt文件出现异常,c#,winforms,C#,Winforms,我正在构建一个WinForm应用程序来管理我想要访问和修改的一些非常简单的数据(在嵌入的.txt文件中)。使用StreamReader可以访问数据,但在修改数据时,该代码会引发“流不可写”异常: System.Reflection.Assembly thisExe; //The first 3 lines are from msdn thisExe = System.Reflection.Assembly.GetExecutingAssembly(); Stream str = thisExe.

我正在构建一个WinForm应用程序来管理我想要访问和修改的一些非常简单的数据(在嵌入的.txt文件中)。使用StreamReader可以访问数据,但在修改数据时,该代码会引发“流不可写”异常:

System.Reflection.Assembly thisExe; //The first 3 lines are from msdn
thisExe = System.Reflection.Assembly.GetExecutingAssembly();
Stream str = thisExe.GetManifestResourceStream("a.b.txt");
StreamWriter sw = new StreamWriter(str);
我尝试了Stream.CanWrite属性,但它是只读的


有没有办法获得该文本文件的CanWrite权限

GetManifestResourceStream
获取的作为返回值的
无法写入。嵌入的资源被编译到您的exe/dll中,不需要修改

清单资源是指 在编译时嵌入到程序集中

请改用或将资源
复制到另一个
,请参阅


您不能修改磁盘上的EXE或DLL。当它们加载到内存中时,由操作系统对其加上的锁保护。和UAC。和典型的反病毒程序。因此,流当然是不可写的。嵌入式资源是只读的。如果需要编写它们,则需要一个存储在AppData中的普通文件。
File.WriteAllText("C:\a.b.txt", Resources.ResourceName);