`
dyllove98
  • 浏览: 1382514 次
  • 性别: Icon_minigender_1
  • 来自: 济南
博客专栏
73a48ce3-d397-3b94-9f5d-49eb2ab017ab
Eclipse Rcp/R...
浏览量:38332
4322ac12-0ba9-3ac3-a3cf-b2f587fdfd3f
项目管理checkList...
浏览量:78642
4fb6ad91-52a6-307a-9e4f-816b4a7ce416
哲理故事与管理之道
浏览量:131791
社区版块
存档分类
最新评论
收藏列表
标题 标签 来源
oracle connect by sql oracle connec connect by sql
select id, level 
from tree t 
start with t.parent_id = 0 
connect by prior t.id = t.parent_id;    
压缩gz 压缩gz 压缩文件
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;

public class FileCompress
{

	// 压缩
	public static void gz(String fromFilePath, String toFilePath) throws IOException
	{
		//读取文件
		InputStream fileIn = new FileInputStream(fromFilePath);
		byte[] b = new byte[fileIn.available()];
		fileIn.read(b);

		
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		GZIPOutputStream gzip = new GZIPOutputStream(out);
		//将文件内容压缩写入ByteArrayOutputStream
		gzip.write(b);
		gzip.close();

		
		//将压缩内容写入新文件
		byte[] ob = out.toByteArray();
		OutputStream fileOut = new FileOutputStream(toFilePath);
		fileOut.write(ob);
		fileOut.flush();
		fileOut.close();
	}

	// 解压缩
	public static void ungz(String fromFilePath, String toFilePath) throws IOException
	{
		//读取文件
		InputStream fileIn = new FileInputStream(fromFilePath);
		byte[] b = new byte[fileIn.available()];
		fileIn.read(b);
		
		//准备写入解压文件中
		OutputStream fileOut = new FileOutputStream(toFilePath);
		
		//将读取文件解压
		ByteArrayInputStream in = new ByteArrayInputStream(b);
		GZIPInputStream gunzip = new GZIPInputStream(in);
		byte[] buffer = new byte[256];
		
		//将压缩内容写入新文件
		int n;
		while ((n = gunzip.read(buffer)) >= 0)
		{
			fileOut.write(buffer, 0, n);
		}
		in.close();
		gunzip.close();
		fileOut.flush();
		fileOut.close();
		
	}
	
	
	public static void main(String[] args) throws IOException
	{
		String fromFile = "c:/1.xml";
		String toFile = "c:/1.gz";
		
		gz(fromFile, toFile);
		//ungz(toFile, fromFile);
	}

}
Global site tag (gtag.js) - Google Analytics