日期:2014-05-19  浏览次数:21078 次

在当前目录创建一个文件夹,然后在文件夹里创建一个文件,然后在文件里写入一些文字?如何写?
在当前目录创建一个文件夹,然后在文件夹里创建一个文件,然后在文件里写入一些文字?如何写?

------解决方案--------------------
当前目录是程序目录,还是系统的当前目录阿?
------解决方案--------------------
System.IO.DirectoryInfo a=System.IO.Directory.CreateDirectory( "a ");
System.IO.StreamWriter sw=System.IO.File.CreateText(a.FullName);
sw.WriteLine( "sdadsasda ");
sw.Close();
------解决方案--------------------
Directory.CreateDirectory (String) 按 path 的指定创建所有目录和子目录。
------解决方案--------------------
using (StreamWriter sw = new StreamWriter( "TestFile.txt "))
{
// Add some text to the file.
sw.Write( "This is the ");
sw.WriteLine( "header for the file. ");
sw.WriteLine( "------------------- ");
// Arbitrary objects can also be written to the file.
sw.Write( "The date is: ");
sw.WriteLine(DateTime.Now);
}
这是写文件和创建文件。
------解决方案--------------------
string dir=Application.StartupPath;
//可以获得应用程序目录