c#中文件操作

   //DirectoryInfo dir = new DirectoryInfo("c:\\");
          //  System.IO .FileSystemInfo[] fis = dir.GetFileSystemInfos();
          //  if (fis[1] is DirectoryInfo )
          //  {
          //      //fis[1]是一个文件夹
          //  }
          //  if (fis[1] is FileInfo)
          //  {
          //      //fis[1]是一个文件
          //  }
        private void operatorFileBtn_Click(object sender, EventArgs e)
        {
            FileInfo fi = new FileInfo("aa.txt");
            if (fi.Exists)
            {
                //向文件中追加信息
                using (StreamWriter sw =fi.AppendText ())
                {
                    sw.Write("这是测试信息:::");
                }
            }
            else
            {
                //创建文件并写入信息
                using (StreamWriter sw = fi.CreateText())
                {
                    sw.Write("创建文件::");
                }
            }
           
        }

        private void readBtn_Click(object sender, EventArgs e)
        {
            FileInfo fi = new FileInfo("aa.txt");
            if (fi.Exists)
            {
                //读取文件内容
                using (StreamReader sr=fi.OpenText())
                {
                    this.richTextBox1.Text = sr.ReadToEnd();
                }
            }
            fi.CopyTo("d:aa.txt");
            fi.Create();
            fi.Delete();
        }

你可能感兴趣的:(文件操作)