C#之IO读写文件方法封装代码
程序员文章站
2023-12-12 20:33:22
具体不做详细介绍了,直接上代码
///
/// 功能:filestream文件流读取文件
///
具体不做详细介绍了,直接上代码
/// <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读写文件方法封装做了详细介绍,希望能够帮助到大家。