当前位置: 移动技术网 > IT编程>开发语言>c# > C#之IO读写文件方法封装代码

C#之IO读写文件方法封装代码

2019年07月18日  | 移动技术网IT编程  | 我要评论

具体不做详细介绍了,直接上代码

/// <summary>
  /// 功能:filestream文件流读取文件
  /// </summary>
  /// <param name="filepath">参数:文件路径</param>
  /// <returns>返回值:streamreader对象</returns>
  public static streamreader readfilebyfs(string filepath)
  {
   filestream fs = null;
   streamreader sr = null;
   try
   {
    fs = new filestream(filepath, filemode.openorcreate, fileaccess.read);
    sr = new streamreader(fs, encoding.default);
   }
   catch (ioexception e)
   {
    throw e;
   }
   return sr;
  }

  代码 2:
      

 /// <summary>
  /// 功能:filestream文件流写文件
  /// </summary>
  /// <param name="filepath">参数:文件路径</param>
  /// <returns>返回值:streamwriter对象</returns>
  public static streamwriter writefilebyfs(string filepath)
  {
   filestream fs = null;
   streamwriter sw = null;
   try
   {
    fs = new filestream(filepath, filemode.openorcreate, fileaccess.write);
    sw = new streamwriter(fs, encoding.default);
   }
   catch (ioexception e)
   {
    throw e;
   }
   return sw;
  }

以上代码针对io读写文件方法封装做了详细介绍,希望能够帮助到大家。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网