zoukankan
html css js c++ java
Net压缩文件流
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO.Compression; using System.IO; namespace gzipfile { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { //文件流 FileStream reader; reader = File.Open("D:\\ddd.txt", FileMode.Open); FileStream writer; writer = File.Create("D:\\ddd.gz"); //压缩相关的流 MemoryStream ms = new MemoryStream(); GZipStream zipStream = new GZipStream(ms, CompressionMode.Compress, true); //往压缩流中写数据 byte[] sourceBuffer = new byte[reader.Length]; reader.Read(sourceBuffer, 0, sourceBuffer.Length); zipStream.Write(sourceBuffer, 0, sourceBuffer.Length); //一定要在内存流读取之前关闭压缩流 zipStream.Close(); zipStream.Dispose(); //从内存流中读数据 ms.Position = 0; //注意,不要遗漏此句 byte[] destBuffer = new byte[ms.Length]; //ms.Read(destBuffer, 0, destBuffer.Length); byte[] header = new byte [10]; ms.Read(header, 0, 10); header[3] = 8; //表示包含文件名信息 byte[] fielContent = new byte[ms.Length -10] ; ms.Read(fielContent, 0, fielContent.Length); string strfilename = "widebright的文件.txt"; //指定初始文件名 //byte [] filename=System.Text.Encoding.Convert(System.Text.Encoding.Default, // // System.Text.Encoding.GetEncoding("ISO-8859-1"), // System.Text.Encoding.Default, // System.Text.Encoding.Default.GetBytes(strfilename)); byte[] filename = System.Text.Encoding.Default.GetBytes(strfilename); writer.Write(header, 0, header.Length); writer.Write(filename, 0, filename.Length); writer.WriteByte(0); //文件名以0 字节结束 writer.Write(fielContent, 0, fielContent.Length); //关闭并释放内存流 ms.Close(); ms.Dispose(); //关闭并释放文件流 writer.Close(); writer.Dispose(); reader.Close(); reader.Dispose(); } } }
查看全文
相关阅读:
SVGEditor
SVG六基本元素
SVG在网页中的四种使用方式
Chrome中java因过期而遭到阻止
Weblogic常见故障常:JDBC Connection Pools
MyBatis java.sql.SQLSyntaxErrorException: ORA-00911: 无效字符
MYBATIS 无效的列类型: 1111
[MyBatis]mapperLocations属性通配符的使用
secureCRT自动化脚本
google protocol buffer的原理和使用(四)
原文地址:https://www.cnblogs.com/javawebsoa/p/2458115.html
最新文章
双人对战的球类游戏ios源代码项目
POJ1258 Agri-Net MST最小生成树题解
UVA 111 (复习dp, 14.07.09)
mother's day.py 母亲节
PL-SQL 包的创建和应用
使用thrift实现了Javaserver和nodejsclient之间的跨平台通信
十二道锋味——既是食,也是人
Visual Prolog 的 Web 专家系统 (10)
#淘宝#复制分享宝贝内容,打开淘宝APP,自己主动弹出宝贝提示信息
接口与抽象类
热门文章
AWS向中国有限预览客户推出多级别AWS支持服务
UVALive
jQuery -> 获取后代元素的三种方法
Workflow相关表简单分析
基于Office 365 无代码工作流分析-表单基本需求分析!
出现二个奇葩bug
[Binary Hacking] ABI and EABI
STL源代码分析--deque
怎样提高hbase的入库性能
SecureCRT 保存FTP用户登录密码
Copyright © 2011-2022 走看看