ArgumentException: Empty path name is not legal. System.IO.StreamWriter..ctor (System.String path, System.Boolean append, System.Text.Encoding encoding, System.Int32 bufferSize, System.Boolean checkHost) (at <7d97106330684add86d080ecf65bfe69>:0) System.IO.StreamWriter..ctor (System.String path, System.Boolean append, System.Text.Encoding encoding, System.Int32 bufferSize) (at <7d97106330684add86d080ecf65bfe69>:0) System.IO.StreamWriter..ctor (System.String path, System.Boolean append, System.Text.Encoding encoding) (at <7d97106330684add86d080ecf65bfe69>:0) (wrapper remoting-invoke-with-check) System.IO.StreamWriter..ctor(string,bool,System.Text.Encoding) System.IO.File.WriteAllText (System.String path, System.String contents, System.Text.Encoding encoding) (at <7d97106330684add86d080ecf65bfe69>:0) System.IO.File.WriteAllText (System.String path, System.String contents) (at <7d97106330684add86d080ecf65bfe69>:0) NewBehaviourScript4+<ReadFiles>d__7.MoveNext () (at Assets/NewBehaviourScript4.cs:37) UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumera
时间: 2023-06-27 18:07:43 浏览: 104
这个错误是因为你传递了一个空路径名给 `StreamWriter` 的构造函数,导致了 `ArgumentException` 异常。你需要检查你的代码,确保你传递给 `StreamWriter` 构造函数的路径名不为空。
此外,在调用 `File.WriteAllText()` 方法时,你可以通过指定编码格式来避免这个问题。例如,你可以使用以下代码:
```
File.WriteAllText(path, contents, Encoding.UTF8);
```
这将使用 UTF-8 编码格式来写入文件,如果你不指定编码格式,默认情况下将使用操作系统的默认编码格式。
相关问题
System.ArgumentException:“Option not supported. Parameter name: srever”
这个错误似乎是因为你在使用某个函数或方法时,传递了一个不支持的选项或参数。具体来说,这个错误信息中提到了一个名为"srever"的参数不被支持。
可能的原因是你拼写了错误的参数名,或者使用了过时的函数或方法。你可以仔细检查一下你的代码,看看是否有任何拼写错误或者调用了不正确的函数或方法。如果你需要更多的帮助,请提供更多的具体信息,我将尽力帮助你解决这个问题。
ArgumentException: Second path fragment must not be a drive or UNC name. Parameter name: path2
这个错误通常是由于使用了不正确的路径格式导致的。请检查你代码中的路径参数,确保它们是正确的。
你可以尝试在路径字符串前加上 `@` 符号,将其转换为 verbatim string,以避免转义字符的问题,例如:
```csharp
string path = @"C:\Users\username\Documents\file.txt";
```
另外,也要确保路径中的斜杠方向正确,Windows系统使用反斜杠 `\`,而Unix或Linux系统使用正斜杠 `/`。如果你需要写跨平台代码,可以使用 `Path.Combine` 方法来连接路径,例如:
```csharp
string path = Path.Combine("C:", "Users", "username", "Documents", "file.txt");
```
这样就可以自动根据操作系统类型来选择正确的路径分隔符。