【winfrom】文本文档

 //FileInfo
        private void button1_Click(object sender, EventArgs e)
        {
            string path = "folder2/mytext1.txt";
            FileInfo fi = new FileInfo(path);
            StreamWriter sw = fi.AppendText();
            fi.Create();
            fi.Open(FileMode.OpenOrCreate,FileAccess.Write);
            fi.OpenRead();
            fi.OpenWrite();
            fi.MoveTo("目标位置");//移动
            fi.CopyTo("目标位置");
            fi.Delete();
        }

  

  // File static类 提供用于创建、复制、删除、移动和打开文件的静态方法,并协助创建 
        private void button2_Click(object sender, EventArgs e)
        {
            string path = "folder2/mytext2.txt";
            //FileStream
            //FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
            //创建
           // FileStream fs = File.Create(path);
           // StreamWriter sw = File.CreateText(path);
           ////打开文件
           //FileStream fs1 = File.Open(path, FileMode.Open, FileAccess.Read);
           //FileStream fs2 = File.OpenRead(path);
           FileStream fs3 = File.OpenWrite(path);
            byte[] bytearr="sss".Select(c=>Convert.ToByte(c)).ToArray();

           fs3.Write(bytearr,0,bytearr.Length);
           fs3.Close();
           StreamReader sr = File.OpenText(path);
           StreamWriter sw = File.AppendText(path);
            //追加
           byte[] bts = File.ReadAllBytes(path);
           File.AppendAllText(path, "dddd",Encoding.UTF8);

           File.Move("原文件路径", "目标路径");
           File.Copy("原文件路径", "目标路径");
           File.Delete(path);
        }

  

posted @ 2018-03-26 08:56  Microera  阅读(223)  评论(0)    收藏  举报