我在用C#打开文件时遇到问题。
我收到了一个需要阅读的文件,当我试图用C#打开它时,出于某种原因无法找到文件。
这里是我的代码:打开没有扩展名的文件
string fullpath = Directory.GetCurrentDirectory() +
string.Format(@"\FT933\FT33_1");
try
{
StreamReader reader = new StreamReader(fullpath);
}
catch(Exception e)
{
Console.WriteLine("The file could not be read:");
Console.WriteLine(e.Message);
}
我尝试打开该文件是内部Debug\FT933\FT33_1
并没有得到推广。
每当我试图从同一个目录打开一个文本文件,我设法这样做。
EDIT:
更精确的是,我认为这个问题,我有是,我不知道如何打开有没有一些推广(如果我更改文件有.TXT extention我不设法打开一个文件)
\ FT933 \ FT33_1。 ? – st78
当我推送属性时它没有扩展它说文件类型是文件 –
在构建路径时,使用'Path.Combine'而不是串联。 – Oded