解压zip文件

687阅读 0评论2010-08-10 ajiejie1
分类:

/**
 * 解压zip文件
 *
 * @param sourceFile,待解压的zip文件;
 *            toFolder,解压后的存放路径
 * @throws Exception
 */
/*
 * public static void zipToFile(String sourceFile, String toFolder) throws
 * Exception {
 *
 * String toDisk = toFolder;//接收解压后的存放路径 ZipFile zfile = new
 * ZipFile(sourceFile);//连接待解压文件 System.out.println("要解压的文件是:" +
 * zfile.getName());
 *
 * Enumeration zList = zfile.entries();//得到zip包里的所有元素 ZipEntry ze = null; byte[]
 * buf = new byte[1024];
 *
 * while (zList.hasMoreElements()) { ze = (ZipEntry) zList.nextElement(); if
 * (ze.isDirectory()) { System.out.println("打开zip文件里的文件夹:" + ze.getName() + "
 * skipped..."); continue; } System.out.println("zip包里的文件: " + ze.getName() +
 * "\t" + "大小为:" + ze.getSize() + "KB");
 *
 * //以ZipEntry为参数得到一个InputStream,并写到OutputStream中 OutputStream outputStream =
 * new BufferedOutputStream( new FileOutputStream(getRealFileName(toDisk,
 * ze.getName()))); InputStream inputStream = new BufferedInputStream(zfile
 * .getInputStream(ze)); int readLen = 0; while ((readLen =
 * inputStream.read(buf, 0, 1024)) != -1) { outputStream.write(buf, 0, readLen); }
 * inputStream.close(); outputStream.close(); System.out.println("已经解压出:" +
 * ze.getName()); } zfile.close(); }
 */
/*
 * private void startIMP(StringBuffer msg) { File srcFilePath = new
 * File(Util.getResourceString("srcFilePath"));
 *
 * File[] srcFiles = srcFilePath.listFiles(); //
 *
 * if (srcFiles.length > 0) { for (int i = 0; i < srcFiles.length; i++) { File
 * file = srcFiles[i]; try { if(file.isFile()){ //doOneFile(file,msg); } } catch
 * (AppException e) {
 *
 * e.printStackTrace(); } } } }
 */
上一篇:usefull sites
下一篇:Work