IO流 , 读取 / 写入

                                      一 , 读取

1.创建文件流

FileStream fs=new FileStream( " 路径 " ,  FileMode.Open );

2.创建读取器

StreamReader sr=new StreamReader( fs   , Encoding.Default );    

3.执行读取操作

string content= sr.ReadToEnd();   //从流的开始读到末尾

textConternt.Text=content;

4.关闭读取器

sr.Close();

5.关闭流

fs.Close();

                               二 .  写入

1.创建文件流

string word=textContent.Txt;

FileStream fs=new FileStream( " 路径 "    ,    FileMode.Create );

2.创建写入器

StreamWriter  sw=new StreamWriter(  fs  );

3.执行写入操作

sw.write( word );

4.关闭写入器

sw.Close();

5.关闭流

fs.Close();

               

       三.    删除

File.Exists(路径)

File.Delete();    / / 删除

               

      四  . 复制 . 

File.Copy( 现在路径 ,  复制路径 );

      五  .  将指定文件移动的新的路径

File.Move(  );

     

六  判断是否存在

bool fa = Directory.Exists( 路径 );

 总结  : 

FileMode 枚举

       1.   方   法

FileMode. Create      / /  覆盖原有内容  

FileMode. Append    / /  追加

FileMode .Open       / / 打开指定文件

FileMode .CreateNew     / /   新建文件,存在就会抛出异常

       2.编码    Encoding

/ /    UTF-8:国际通用编码

/ /    GBK

/ /    GB2312

/ /    Default

        3  .  xxxxx

FileStream    文件流

StreamReader  读取器

StreamWrite  写入器

         4 .   删除

file.Delete();   彻底删除不经回收站

原文地址:https://www.cnblogs.com/1612ss/p/7101469.html