文件未发现异常。但它的存在 [英] File not found Exception.. But it's there
问题描述
嘿,这将是那些愚蠢的问题之一。我想拿起文件在本地系统中,我不断收到一个 FileNotFoundException异常
抛出。
Hey this is going to be one of those dumb questions. I am trying to pick up a file on my local system and I keep getting a FileNotFoundException
thrown.
有人让我直接请:)
if( File.Exists(@"C:\logs\hw-healthways-prod_2009-08-26.tar"))
{
Console.WriteLine("Yay");
}
else
{
throw new FileNotFoundException();
}
尝试过将文件移动到相同的位置执行的应用程序,也做了以下内容:
Tried moving the file into the same location as the executing application and did the following:
if( File.Exists("hw-healthways-prod_2009-08-26.tar"))
同样的事情。
Same thing.
然后,我做了一个随机的txt文件,并停放在那里太..me.txt
Then I made a random txt file and parked it there too.. "me.txt"
和它的工作原理?所以,你的事情的文件名是什么问题?
And it works?! So you thing the file name is the problem?
推荐答案
试着做 Directory.GetFiles(@C:\日志)
。这有可能是有问题的文件已经由Windows资源管理器(presumably你来自哪里读文件的财产?)越来越PTED除$ P $单程奇怪的字符,但由.NET Framework以不同的方式。这可能发生,如果你有UTF-8字符的文件名(可能是一个短划线?)。
Try doing Directory.GetFiles(@"C:\logs")
. It's possible that the file in question has odd characters that are getting interpreted one way by Windows Explorer (presumably where you're reading "the file's property" from?) but a different way by the .NET Framework. This can happen if you have UTF-8 characters in the filename (perhaps an en dash?).
这篇关于文件未发现异常。但它的存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!