C# Byte[]数组读取和写入文件
来源:互联网 发布:阿里云icp备案系统 编辑:程序博客网 时间:2024/06/05 19:33
protected void ByteToString_Click(object sender, EventArgs e) { string content = this.txtContent.Text.ToString(); if (string.IsNullOrEmpty(content)) { return; } //string 转为byte数组 byte[] array = Encoding.UTF8.GetBytes(content); //将byte数组转为string string result = Encoding.UTF8.GetString(array); Response.Write(result); } //利用byte[]数组写入文件 protected void writerFile_Click(object sender, EventArgs e) { string content = this.txtContent.Text.ToString(); if (string.IsNullOrEmpty(content)) { return; } //将string转为byte数组 byte[] array = Encoding.UTF8.GetBytes(content); string path = Server.MapPath("/test.txt"); //创建一个文件流 FileStream fs = new FileStream(path, FileMode.Create); //将byte数组写入文件中 fs.Write(array, 0, array.Length); //所有流类型都要关闭流,否则会出现内存泄露问题 fs.Close(); Response.Write("保存文件成功"); } //利用byte[]数组读取文件 protected void readFile_Click(object sender, EventArgs e) { string path = Server.MapPath("/test.txt"); FileStream fs = new FileStream(path, FileMode.Open); //获取文件大小 long size = fs.Length; byte[] array = new byte[size]; //将文件读到byte数组中 fs.Read(array, 0, array.Length); fs.Close(); //将byte数组转为string string result = Encoding.UTF8.GetString(array); Response.Write(result); }
阅读全文
0 0
- C# Byte[]数组读取和写入文件
- c#文件读取和写入
- 读取文件到byte[]数组,将byte[]写入到指定文件中
- 将byte数组写入文件
- c#大文件读取和写入数据库
- c# 读取和写入txt文件
- C#写入和读取ini文件
- C#大文件读取和写入数据库
- C#文件的读取和写入
- C# winform写入和读取TXT文件
- C#文件写入和读取简单使用
- C# 读取写入文件
- 文件读取和写入
- 文件读取和写入
- 文件读取和写入
- C#中读取文件和写入文件的类
- 文件和byte数组
- c# 将byte[]数组写入文件并添加空格(回车)操作
- 关于Parameter 'xxx' not found. Available parameters are [0, 1, 2, param3, param1, param2]错误
- Redis 事务
- JVM常见的启动参数
- 【转】 React-Native调用浏览器和第三方APP
- eclipse点出class文件的配置方法
- C# Byte[]数组读取和写入文件
- 第十三章-栈视图
- Manifest merger failed with multiple errors
- Java 8 中 Date与LocalDateTime、LocalDate、LocalTime互转
- 数学 方程的解
- c raft
- 第5章 排序 —— 5.6 [PTA]统计工龄
- 装个驱动装了半天...
- js获取数组中最小的值的方法 Math.min.apply(),apply(),call()方法使用