【发布时间】:2011-07-06 18:51:06
【问题描述】:
我正在尝试将文件保存在路径 WindowsFormsApplication1\WindowsFormsApplication1\SaveFile 但以下代码返回“DirectoryNotFound”异常并显示消息:
找不到路径的一部分 'D:\WindowsFormsApplication1\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\SaveFile\Hello.tx
String Path = @".\SaveFile\Hello.txt";
FileInfo info = new FileInfo(Path);
if (!info.Exists)
{
using (StreamWriter writer = info.CreateText())
{
writer.WriteLine("HELLO");
}
}
谁能告诉我应该如何在指定完整路径的情况下将文件保存在我想要的文件夹中?
【问题讨论】:
-
错误的级别太多了。如果您不想指定要保存文件的文件夹,如何将文件保存到文件夹中?
-
我想将我的文件保存在“WindowsFormsApplication1\WindowsFormsApplication1\SaveFile”文件夹中,并指定完全合格的 URL。
-
@Stardust:那么你需要运行应用程序,当前目录设置为“D:\WindowsFormsApplication1\WindowsFormsApplication1\WindowsFormsApplication1”。
-
在写入之前,您甚至不会尝试验证目录是否存在。