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");
}
}
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");
}
}