具体不做详细介绍了,直接上代码
/// <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读写文件方法封装做了详细介绍,希望能够帮助到大家。
如对本文有疑问, 点击进行留言回复!!
使用Visual Studio2019创建C#项目(窗体应用程序、控制台应用程序、Web应用程序)
C#实现获取本地内网(局域网)和外网(公网)IP地址的方法分析
网友评论