2017-06-16 175 views
2

我的项目没有找到肯定存在的文件。我正在使用斯坦福大学的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? False 

怎么能File.Exists()可能会被返回false?目录的

截图: enter image description here

+0

jar root不是正确的物理路径,请确保路径正确。 – 2017-06-16 07:54:11

+0

@TAHASULTANTEMURI这是一个非常有效的路径,不确定你的意思。 – Rob

+0

首先尝试打开运行命令并运行此路径,如果它是有效的将不会有错误。 – 2017-06-16 07:55:51

回答

2

这问题的意见被整理出来。使用FileStream打开文件会引发'System.IO.PathTooLongException'异常。如果File.Exists()遇到任何错误(例如文件路径太长),则返回false。

@Abbas提供了这个链接,固定的问题,可能会有所帮助: Why does System.IO.File.Exists(string path) return false?

谢谢大家!