我的项目没有找到明确存在的文件。我正在使用斯坦福NLP库,并得到了我开始调试的文件未找到异常。
下面是我的测试代码:
String jarRoot = @"stanford-corenlp-full-2016-10-31\stanford-corenlp-full-2016-10-31\stanford-corenlp-3.7.0-models\edu\stanford\nlp\models\pos-tagger\english-left3words\";
foreach (String fName in Directory.GetFiles(jarRoot))
{
Console.WriteLine("File in jarRoot: " + fName);
Console.WriteLine("File exists? " + File.Exists(fName));
}输出:
File in jarRoot: stanford-corenlp-full-2016-10-31\stanford-corenlp-full-2016-10-31\stanford-corenlp-3.7.0-models\edu\stanford\nlp\models\pos-tagger\english-left3words\english-left3words-distsim.tagger
File exists? False
File in jarRoot: stanford-corenlp-full-2016-10-31\stanford-corenlp-full-2016-10-31\stanford-corenlp-3.7.0-models\edu\stanford\nlp\models\pos-tagger\english-left3words\english-left3words-distsim.tagger.props
File exists? FalseFile.Exists()怎么可能返回false呢?
目录截图:

发布于 2017-06-16 16:52:09
这一点在问题的评论中得到了解决。使用FileStream打开文件时会抛出'System.IO.PathTooLongException‘异常。如果File.Exists()遇到任何错误,比如文件路径太长,它只会返回false。
@Abbas提供了这个链接,修复了这个问题,可能会有帮助:Why does System.IO.File.Exists(string path) return false?
谢谢大家!
https://stackoverflow.com/questions/44583787
复制相似问题