为什么System.IO.File.Exists(字符串路径)返回false? [英] Why does System.IO.File.Exists(string path) return false?

查看:617
本文介绍了为什么System.IO.File.Exists(字符串路径)返回false?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

System.IO.File.Exists(string path)

返回始终为假,即使文件存在指定的路径上。还有什么是可能的解决方案?

returns always false, even when the file exists on the specified path. What could be the possible solution?

推荐答案

这很可能是一个权限问题。从文档

It could well be a permission problem. From the documentation:

的存在如果尝试,以确定是否存在指定的文件中出现任何错误方法返回false。这可能发生在引发异常,如传递一个文件名以无效字符或过多的字符,发生故障或丢失的磁盘的情况下,或者如果调用方没有权限读取该文件。

The Exists method returns false if any error occurs while trying to determine if the specified file exists. This can occur in situations that raise exceptions such as passing a file name with invalid characters or too many characters, a failing or missing disk, or if the caller does not have permission to read the file.

看到发生的事情是刚刚尝试读取文件的一种方法(例如,使用 File.OpenRead )。我会感到惊讶,如果的成功的 - 但如果失败,该异常应该给你更多的信息。

One way of seeing what's happening is to just try to read the file (e.g. with File.OpenRead). I'd be surprised if that succeeds - but if it fails, the exception should give you more information.

这篇关于为什么System.IO.File.Exists(字符串路径)返回false?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆