解压压缩的*.txt.Z文件

	/** 
     * 解压zip文件
     * @param zPath 解压文件存放路径
     * @param oPath 解压后的存放路径 
     * @param isNeedDelSrc 解压后是否删除
     * @throws Exception 
     **/ 
     public static void ZDecodes(String zPath, String oPath,boolean isNeedDelSrc) throws Exception{
     
        OutputStream outputStream = null;  
        InputStream in = null;  
        try {
     
            File file = new File(oPath); //解压后的存放路径  
            if (!file.exists()) file.createNewFile();  
            outputStream = new FileOutputStream(file);  
            in = new ZDecodes(new FileInputStream(new File(zPath)));//需要解压的文件  
            byte[] buf = new byte[8192];  
            while (true) {
     
                int got = in.read(buf);  
                if (got < 0)  break;  
                outputStream.write(buf, 0, got);  
            }  
            outputStream.flush();  
        } finally {
     
            if (null != outputStream) outputStream.close();  
            if (null != in) in.close();  
        }  
  		//解压后是否删除压缩包
        if(isNeedDelSrc){
     
            FileUtils.deleteFile(zPath);  
        }  
    }  
  
    public static void main (String args[])  throws Exception {
     
       String zPath = "D:/XXX.txt.Z";//需要解压的文件  
       String oPath = "D:/222/XXX.txt";//解压后的存放路径  
        ZDecodes.ZDecodes(zPath, oPath, true);  
    }  
}  

工具类:

import java.io.*;  
  
  
public class ZDecodes extends FilterInputStream {
     
  
  
    /** 
     * @param is the input stream to decompress 
     * @exception IOException if the header is malformed 
     */  
    public ZDecodes(InputStream is)  throws IOException  
    {
     
        super(is);  
        parse_header();  
    }  
  
  
    byte[] one = new byte[1];  
    public synchronized int read() throws IOException  
    {
     
        int b = in.read(one, 0, 1);  
        if (b == 1)  
            return (one[0] & 0xff);  
        else  
            return -1;  
    }  
  
  
    // string table stuff  
    private static final int TBL_CLEAR = 0x100;  
    private static final int TBL_FIRST = TBL_CLEAR + 1;  
  
    private int[]  tab_prefix;  
    private byte[] tab_suffix;  
    private int[]  zeros = new int[256];  
    private byte[] stack;  
  
    // various state  
    private boolean block_mode;  
    private int  n_bits;  
    private int  maxbits;  
    private int  maxmaxcode;  
    private int  maxcode;  
    private int  bitmask;  
    private int  oldcode;  
    private byte finchar;  
    private int  stackp;  
    private int  free_ent;  
  
    // input buffer  
    private byte[]  data = new byte[10000];  
    private int     bit_pos = 0, end 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值