unity游戏开发-C#语言基础篇(File类相关操作)

 class Program
    {
        const string url = @"D:\Hello world!\test.txt";//绝对路径
        static void Main(string[] args)
        {
             //文件
            FileInfo myFile = new FileInfo(url);
            Console.WriteLine(myFile.Exists);//执行是否存在文件,返回布尔值


            //练习

            FileInfo myFile = new FileInfo(url);
            Console.WriteLine(myFile.Exists);
            Console.WriteLine(myFile.Length);//汉字是两个字节 字节数
            Console.WriteLine(myFile.IsReadOnly);//判断是否是 只读的·
            Console.WriteLine(myFile.IsReadOnly = true);// 改变 只读的 值·
            Console.WriteLine(myFile.Directory);//返回路径 还可以点出方法
            Console.WriteLine(myFile.DirectoryName);//返回字符串
            FileInfo myFile1 = new FileInfo(@"C:\Users\Administrator\Desktop\wenjianxia\123.txt");
            myFile1.Delete();
            FileInfo myFile2 = new FileInfo(@"C:\Users\Administrator\Desktop\wenjianxia\456.txt");
            myFile.CopyTo(@"C:\Users\Administrator\Desktop\newwenjianjia\789.txt");
            Console.WriteLine(myFile.CreationTime); //文件创建时间
            myFile.MoveTo(@"D:\newwenjianxia\test.txt");//移动文件


            //文件夹
            DirectoryInfo myDire = new DirectoryInfo(@"D:\Hello world!\test1");
            if (!myDire.Exists)
            {
                myDire.Create();//创建文件夹
            }
            Console.WriteLine(myDire.FullName);//返回文件名


            Console.WriteLine(myDire.GetFiles());//获得文件夹目录的文件
            FileInfo[] f = myDire.GetFiles();


            FileInfo myFile1 = new FileInfo(@"D:\Hello world!\test1\testtt.txt");
            for (int i = 0; i < 100; i++)
            {

                DirectoryInfo myDire = new DirectoryInfo(@"D:\Hello world!\test1"+i);
                if (!myDire.Exists)
                {
                    myDire.Create();//创建文件
                }
            }
            Console.ReadKey();
        
        }
    }

你可能感兴趣的:(unity游戏开发-C#语言基础篇(File类相关操作))