目前遇到这样的需求
读取一个文本文件source.txt,按照文本内容拆分成几个不同的文件,同时进行Gzip的压缩,如:a.gzip,b.gzip,c.gzip...
目前我是这样做的
逐行读取文本,达到拆分条件,创建文件,能实现创建成a.txt,b.txt,c.txt...
但是有没有方法直接读取文本,拆分后,直接创建成gzip格式,也就是不要再对生成的a.txt进行压缩处理。
请大家指教!
读取一个文本文件source.txt,按照文本内容拆分成几个不同的文件,同时进行Gzip的压缩,如:a.gzip,b.gzip,c.gzip...
目前我是这样做的
逐行读取文本,达到拆分条件,创建文件,能实现创建成a.txt,b.txt,c.txt...
但是有没有方法直接读取文本,拆分后,直接创建成gzip格式,也就是不要再对生成的a.txt进行压缩处理。
请大家指教!
StringBuilder strHeaderBuilder = new StringBuilder(line);
StreamReader strReader = null;
byte[] buffer = null;
FileStream destinationStream = null;
GZipStream compressedStream = null;line = strReader.ReadLine();
while (strReader.EndOfStream == false)
{
if (string.IsNullOrEmpty(line) == false && line[0] == '1')
{
break;
}
//Header
strHeaderBuilder.AppendLine(line);
line = strReader.ReadLine();
}string tmpPath = Path.Combine(txtDestination.Text, beginLines[1].Trim() + '.' + fileName + ".gzip");
destinationStream = new FileStream(tmpPath, FileMode.OpenOrCreate, FileAccess.Write);
compressedStream = new GZipStream(destinationStream, CompressionMode.Compress);buffer = new byte[strHeaderBuilder.Length];
compressedStream.Write(buffer, 0, buffer.Length);贴上部分代码,请大家帮忙看看,怎么生成的gzip文件,用记事本打开后全是"NULL"呢?这是正常的吗?