我试图看看图片是否存在,但这表示不存在,路径是正确的!路径是正确的,它有一张图片,但这总是去"别的".
string path = @"c:\folder\pic.jpg";
if (File.Exists(path))
{
//Do something here
}
else
{
}
Run Code Online (Sandbox Code Playgroud)
您正在尝试查看是否存在使用的文件夹File.Exists
.这是不正确的 - 目录会失败.
使用Directory.Exists
查找是否存在一个目录.
string path = @"c:\folder";
if (Directory.Exists(path))
{
//Do something here
}
else
{
}
Run Code Online (Sandbox Code Playgroud)
另一个复杂因素是您的应用程序运行的帐户需要具有读取路径的权限 - 如果它没有权限,即使路径存在,这仍然会失败.
归档时间: |
|
查看次数: |
2978 次 |
最近记录: |