我正在尝试使用 File.ReadAllText 和 FileStream 读取文本文件,但由于某种原因,我每次都收到 System.UnauthorizedAccessException。
class consultas
{
public consultas()
{
}
private string Inativos = @"C:\Users\Mathias Cruz\Desktop\helloWorld\helloWorld\Consultas";
public string getInativos()
{
try
{
// string path = Directory.GetCurrentDirectory();
this.Inativos = File.ReadAllText(this.Inativos);
}
catch(Exception e)
{
throw e;
}
return this.Inativos;
}
}
Run Code Online (Sandbox Code Playgroud)
为什么?我在该文件夹中有权限,为什么会出现此异常?
c# ×1