⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gsunzip.java

📁 一个日本流行的,功能较全的开源Web办公管理(Groupware)系统。
💻 JAVA
字号:
package jp.co.sjts.gsession.tools.archive;

import java.io.File;
import java.io.FileInputStream;
import java.io.BufferedInputStream;
import java.io.FileOutputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.CRC32;
import java.util.zip.ZipInputStream;
import java.util.zip.CheckedInputStream;

public class GSUnZip {

	public String fname = null;
	public String pathname = null;

	public GSUnZip(String fname,String pathname) {
		this.fname = fname;
		this.pathname = pathname;
	}

	public GSUnZip(File file,File path) {
		this.fname = file.getPath();
		this.pathname = path.getPath();
	}

	public void write() {
		try {

			byte[] buf = new byte[1024*8];

			FileInputStream fi = new FileInputStream(fname);
			CheckedInputStream csumi = new CheckedInputStream(fi,new CRC32());
			ZipInputStream in = new ZipInputStream(new BufferedInputStream(csumi));
			ZipEntry ze;

			ByteArrayOutputStream bao = new ByteArrayOutputStream();
			while((ze = in.getNextEntry()) != null) {
				bao.reset();
				File file = new File(ze.getName());
				if(ze.getName().lastIndexOf(File.separator) == ze.getName().length() - 1) {
					makeDirs(file);
				}
				else {
					File file2 = new File(file.getParent() + File.separator);
					if( !file2.exists() ) {
						makeDirs(file2);
					}

				//	int result;
				//	do {
				//		result = in.read(buf,0,buf.length);
				//		if(result != -1)
				//			bao.write(buf,0,result);
				//	}while (result == buf.length);
					int r;
					while((r = in.read()) != -1) {
						Integer b = new Integer(r);
						bao.write(b.byteValue());
					}

					byte[] data = bao.toByteArray();
					FileOutputStream fo = new FileOutputStream(pathname + ze.getName());
					BufferedOutputStream bos = new BufferedOutputStream(fo);
					fo.write(data);
					fo.close();
				}
			}
			in.close();
		}
		catch(Exception e) {
			System.err.println(e);
		}
	}

	private void makeDirs(File dir) {
		File file = null;
		if(dir.isDirectory())
			file = dir;
		else
			file = new File(dir.getPath() + File.separator);

		int index = 0;
		String name = file.getPath() + File.separator;
		for(int i=0;i<name.lastIndexOf(File.separator);i=index) {
			index = name.indexOf(File.separator,index) + 1;
			File file2 = new File(name.substring(0,index));
			if(!file2.exists())
				file2.mkdir();
		}
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -