在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
File的静态类: 包含的方法: Exists(Filename)-检查制定文件是否存在。 Copy(“TheSource File”,"The new file")--将文件从原位置复制到目标位置 Create()--从规定的路径创建文件 Delete()--删除文件 Open()--从规定的路径上返回FileStream对象 Move()--将制定的文件移动到新位置,可以在新位置为文件规定不同的名称! FileInfo是非静态类。没有静态方法! 获取逻辑盘: string[] driver = Directory.GetLogicalDrives(); 获取应用程序当前的工作目录 string path = Directory.GetCurrentDirectory(); 获取子目录的文件名: string fileName = Path.GetFileName(@"d:\txt\txt.txt");//return txt.txt 获取目录内的文件名列表 string[] getF = Directory.GetFiles(@"d:\txt\");
ConsoleApplication1
{ class Program { static void Main(string[] args) { FileInfoTest(); FileTest(); Dirt(); Console.ReadKey(); } static void FileInfoTest() { FileInfo fl = new FileInfo(@"D:\txt\txt.txt"); if (fl.Exists) { Console.WriteLine("The file exist!"); } else { Console.WriteLine("The fiel is not exist!"); } } static void FileTest() { if (File.Exists(@"D:\txt\txt.txt")) { Console.WriteLine("The file is exist ,it was checked by the static class File!"); // File.Copy(@"d:\txt\txt.txt",@"d:\txt\xx\t.txt"); } else { Console.WriteLine("The file is not exist!"); } } static void Dirt() { string[] driver = Directory.GetLogicalDrives(); string path = Directory.GetCurrentDirectory(); Console.WriteLine(path); string fileName = Path.GetFileName(@"d:\txt\txt.txt"); string[] getF = Directory.GetFiles(@"d:\txt\"); foreach (string name in getF) { Console.WriteLine(name); } Console.WriteLine("The file name is {0}",fileName); foreach (string arg in driver) { Console.WriteLine(arg); } } static void CreateDirt() { DirectoryInfo dirIn = new DirectoryInfo(); } } }
|
请发表评论