rar

package com.mschn.elife.achievement.bean;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.UUID;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;
public class File1 {
    
/*    public static void readZipFile(String file) throws Exception {    
        
           ZipFile zf = null;
           zf = new ZipFile(file);  
           InputStream in = new BufferedInputStream(new FileInputStream(file));  
           ZipInputStream zin = new ZipInputStream(in);  
           ZipEntry ze;  
           while ((ze = zin.getNextEntry()) != null) {  
               if (ze.isDirectory()) {
               } else {  
                   System.err.println("file - " + ze.getName() + " : "  
                           + ze.getSize() + " bytes");  
                   long size = ze.getSize();  
                   if (size > 0) {  
                       BufferedReader br = new BufferedReader(  
                               new InputStreamReader(zf.getInputStream(ze)));  
                       String line;  
                       while ((line = br.readLine()) != null) {  
                           System.out.println(line);  
                       }  
                       br.close();  
                   }  
                   System.out.println();  
               }  
           }  
           zin.closeEntry();  
       }   
    *//**
     * 文件/文件夹压缩成RAR格式
     * rarName 压缩后的压缩文件名(不包含后缀)
     * fileName 需要压缩的文件名(必须包含路径)
     * destDir 压缩后的压缩文件存放路径
     * password 解压密码
     * @return
     *//*
    public static String RARFile(String rarName, String fileName, String destDir,
            String password) {
       String  rarCmd ="C:\\Program Files\\WinRAR\\WinRAR.exe a -hp" + password + " -ibck -r -k " + destDir + rarName
                + ".zip " + fileName;
        Process p = null;
        int exitVal = 0;
        try {
            Runtime rt = Runtime.getRuntime();
            System.out.println(rarCmd);
            p = rt.exec(rarCmd);
            exitVal = p.waitFor();
            if (exitVal == 0)
            p.destroy();//结束程序占用
        } catch (Exception e) {
            System.out.println(e.getMessage());
        } finally {
            if (exitVal == 0)
            p.destroy();//结束程序占用
        }
        return rarName;
    }
     
    public static void main(String[] args) throws Exception {
        try {  
              RARFile("ak47", "C:\\Users\\Administrator\\Desktop\\abc.txt", "C:\\Users\\Administrator\\Desktop\\", "000000");
           } catch (Exception e) {  
               // TODO Auto-generated catch block  
               e.printStackTrace();  
           }  
    }*/
    public static String winRar(String zipFileName,int password,String savePath){  
        String  rarCmd ="C:\\Program Files\\WinRAR\\WinRAR.exe x -hp" + password + " -ibck " + zipFileName+" "+savePath;
        System.out.println(rarCmd);
        Process p = null;
        int exitVal = 0;
        try {
            Runtime rt = Runtime.getRuntime();
            p = rt.exec(rarCmd);
            exitVal = p.waitFor();
            if (exitVal == 0)
            p.destroy();//结束程序占用
        } catch (Exception e) {
            System.out.println(e.getMessage());
        } finally {
            if (exitVal == 0)
            p.destroy();//结束程序占用
        }
        return "pendingName";
    }
    public static void main(String[] args) {
        winRar("C:\\Users\\Administrator\\Desktop\\abc.zip",123456, "C:\\Users\\Administrator\\Desktop");
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值