- 浏览: 425068 次
- 性别:
- 来自: 上海
-
文章分类
- 全部博客 (203)
- 管理 (9)
- 情感 (3)
- 技术 (43)
- jfreeChart (5)
- unix (6)
- webService (3)
- 权限管理 (2)
- spring (3)
- log4j (2)
- java性能测试 (2)
- dwr (1)
- 数据迁移 (4)
- derby数据库基础 (1)
- jsp前台 (4)
- 线程 (6)
- 企业信息化 (2)
- 技术基础 (2)
- 经典算法 (1)
- 数据库性能 (7)
- 个人规划 (8)
- xml (2)
- ftp传输 (1)
- socket (3)
- java技术之正则表达式 (2)
- java技术之io操作 (1)
- java技术之常用命令程序使用方法 (1)
- interview (8)
- eclipse插件安装 (3)
- UML (1)
- oracle (29)
- java (3)
- 航空信息 (3)
- 读书 (1)
- Intellij idea (0)
- linux (24)
- 服务器架构 (4)
- weblogic (3)
最新评论
-
tuspark:
关于eclipse插件安装方法,这里文章图文并茂,讲解的最详细 ...
eclipse插件安装方法总结 -
swanky_yao:
非常不错 受益匪浅
j2ee异常处理机制 -
菜鸟不再菜:
如果能拿一个项目的例子来说明一下就好了~
j2ee异常处理机制 -
Q.Lee:
不出现异常了,但是访问http://localhost:808 ...
dwr使用异常 -
Q.Lee:
崩溃。。。。。
dwr使用异常
package com.sjs; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.Enumeration; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import java.util.zip.ZipOutputStream; public class UtilZip { public static void main(String[] args) throws Exception { String type = args[0];// 文件压缩类型 // 如果命令行压缩,目前只支持压缩单个档案 if ("zip" == type) { String src = args[1];// 源文件 String[] srcFile = { src }; String savePath = args[2];// 目标文件目录 String destFile = args[3];// 目标文件名称 // // 调用压缩文件方法 zip(srcFile, savePath, destFile); } else if ("unzip" == type) { String savePath = args[1];// 解压文件之后所放置的目录 String destFile = args[2];// 源压缩文件 // 调用压缩文件方法 unZip(destFile, savePath); } else { throw new RuntimeException(" $1 must be zip or unzip ."); } } /** * * @param source * 源文件 * @param savePath * 压缩文件路径 * @param destFileName * 压缩文件名 * @throws Exception * * @Description 压缩文件方法 */ public static void zip(String[] source, String savePath, String destFileName) throws Exception { // 检查被压缩元素是否存在,并创建目标目录 init(source, savePath, destFileName); File destFile = new File(savePath, destFileName); FileInputStream fis = null; FileOutputStream fos = null; ZipOutputStream zos = null; try { // 打开目标文件 fos = new FileOutputStream(destFile); } catch (FileNotFoundException e) { throw new RuntimeException("open" + destFile.getAbsolutePath() + "operate fail cause " + e); } zos = new ZipOutputStream(fos); try { for (int i = 0; i < source.length; i++) { File srcFile = new File(source[i]); // 将盘符去掉:由“c:/home”变成“home”;即把绝对路径换成相对路径进行压缩 String entryPath = source[i].substring(source[i].indexOf("/") + 1, source[i].length()); if (srcFile.isDirectory()) { String parent = srcFile.getParent(); System.out.println("parent :" + parent); // 压缩目录档案 zip(zos, srcFile, parent); } // 压缩非目录档案 if (!(srcFile.isDirectory())) { fis = new FileInputStream(new File(source[i])); ZipEntry entry = new ZipEntry(entryPath); zos.putNextEntry(entry); writeFile(fis, zos); } } } catch (Exception e) { throw e; } finally { try { if (zos != null) { zos.close(); } } catch (IOException e) { e.printStackTrace(); } } } /** * * @param zipOutputStream * 压缩文件输出流 * @param file * 被压缩文件 * @param src * 被压缩文件的父目录 */ private static void zip(ZipOutputStream zipOutputStream, File file, String src) { if (file.isDirectory()) { File[] fileList = file.listFiles(); String entryPath = file.getAbsolutePath().substring(src.length()) + "/"; try { // ##### 对目录进行处理,如果没有此句,则空目录和非空目录都不会被压缩进去 zipOutputStream.putNextEntry(new ZipEntry(entryPath)); } catch (Exception e) { e.printStackTrace(); } for (int i = 0; i < fileList.length; ++i) zip(zipOutputStream, fileList[i], src); } else { FileInputStream in = null; try { String fileName = file.getAbsolutePath(); in = new FileInputStream(file); String entryPath = fileName.substring(src.length()); // 将此语句解注,配合将“#####”语句注释掉,可以将所有目录去掉,只压缩文件,不会由目录出现(即压缩文件中不会由目录结构) // entryPath = entryPath.substring(entryPath.lastIndexOf("\\") + // 1); ZipEntry entry = new ZipEntry(entryPath); zipOutputStream.putNextEntry(entry); writeFile(in, zipOutputStream); } catch (Exception e) { throw new RuntimeException("zip file " + file.getAbsolutePath() + " has failed."); } finally { if (in != null) try { in.close(); } catch (Exception e) { e.printStackTrace(); } } } } // 将数据写入输出流 private static void writeFile(InputStream fis, OutputStream zos) throws IOException { int length = 0; byte[] buffer = new byte[1024]; while ((length = fis.read(buffer)) != -1) { zos.write(buffer, 0, length); } zos.flush(); } /** * * @param source * @param savePath * @param destFileName * @Description: 初始化压缩文件的条件 */ private static void init(String[] source, String savePath, String destFileName) { if (source == null) { throw new IllegalArgumentException("the source file can't be null."); } if (source.length == 0) { throw new IllegalArgumentException("the source file is empty."); } File sourceFile = null; for (int i = 0; i < source.length; i++) { sourceFile = new File(source[i]); if (!sourceFile.exists()) { throw new IllegalArgumentException("the file" + source[i] + "is not exist."); } } File destFile = new File(savePath); if (!destFile.exists()) { destFile.mkdirs(); } } public static String[] unZip(String fileName, String savePath) { ArrayList<String> fileList = new ArrayList<String>(); File unzipfile = null; InputStream input = null; OutputStream output = null; ZipFile zipFile = null; try { zipFile = new ZipFile(new File(fileName)); } catch (Exception e) { throw new RuntimeException("Zip File has Exception " + e); } Enumeration enumeration = zipFile.entries(); try { do { ZipEntry entry = (ZipEntry) enumeration.nextElement(); unzipfile = new File(savePath, entry.getName()); input = zipFile.getInputStream(entry); if (entry.isDirectory()) { unzipfile.mkdirs(); } if (!(entry.isDirectory())) { output = new FileOutputStream(unzipfile); writeFile(input, output); try { if (input != null) input.close(); if (output != null) output.close(); } catch (Exception e1) { e1.printStackTrace(); } } fileList.add(entry.getName()); } while (enumeration.hasMoreElements()); } catch (Exception e) { throw new RuntimeException(e); } finally { try { if (zipFile != null) { zipFile.close(); } } catch (Exception e1) { e1.printStackTrace(); } } String[] str = new String[fileList.size()]; for (int j = 0; j < fileList.size(); ++j) str[j] = ((String) fileList.get(j)); return str; } }
发表评论
文章已被作者锁定,不允许评论。
-
WIN10 下 IE11 F12开发者工具无法debug断点调试js
2016-03-03 12:26 10181前段时间买了新电脑,安装的是win10系统,开发程序时需要 ... -
更改ejs模板后缀.ejs为.html
2015-03-25 16:12 761app.engine('.html', require('e ... -
npm设置http代理
2015-03-25 15:32 1372node.js 的npm命令是node.js的包管理工具,安 ... -
ERROR Deployer not found: git
2015-03-23 01:39 0出现该问题基本原因是由于没有安装hexo-deployer- ... -
webstorm install
2015-03-22 23:36 1009在安装hexo前,需要先安装webstorm,并通过web ... -
centos6 git github
2015-03-22 23:30 901git的出现让传统的svn陷入尴尬的境地,分布式的版本控制 ... -
centos6 nodejs install
2015-03-22 22:02 664准备命令: yum -y install gcc ma ... -
fcitx安装
2015-03-21 00:13 869CentOS安装fcitx方法 因为选择的是最小安装 ... -
_jspxFactory nullpointException
2012-11-01 11:12 1064exception org.apache.jas ... -
preparedstatement execute()操作成功!但是返回false
2012-10-22 10:58 2847boolean b = ps.execute();//这 ... -
如何用 SQL Tuning Advisor (STA) 优化SQL语句
2011-08-26 10:46 1103在Oracle10g之前,优化SQL是个比较费力的技术活, ... -
谈谈对于技术面试的心得体验
2011-02-10 14:10 998只要是招一个技术人 ... -
eclipse3.4从svn导出后html中文乱码
2010-09-25 11:54 1863问题描述:从svn中check out一个工程,然后给工程设置 ... -
使用break+label配合跳出多重循环
2010-03-24 10:34 1780签语句是在某个语句前面加上个标识符以及一个冒号 . 标签在 b ... -
工程中使用java代码加载第三方jar文件
2010-03-24 10:33 4297package com.send.start; impo ... -
jar命令使用遇到问题
2010-03-24 10:32 1338jar cvfm stup.jar ../list.txt - ... -
数据库中取出的值判断
2010-03-05 16:56 1053//数据库中取出的值判断时,经常出现使用null和“”都判断不 ... -
批处理删除svn文件与clas文件
2010-03-04 11:01 1622package com.delete.dir; impo ... -
java程序中调用数据库中的存储过程
2009-11-27 12:32 1032public static void aa(String jo ... -
java代码实现运行cmd命令
2009-11-21 19:06 1975命令工厂: public class CommandFact ...
相关推荐
总之,压缩与解压缩文件是信息技术中的基本操作,而霍夫曼编码是其中一种重要的无损压缩方法。理解其原理并能熟练运用,不仅可以优化数据传输,还能在资源有限的情况下提高效率。通过团队项目和个人小结的文档,我们...
在Java编程语言中,文件的压缩与解压缩是常见的数据处理操作,特别是在数据传输、存储优化和备份场景中。本实践项目围绕这个主题展开,包括源代码和相关的论文,为学习者提供了深入理解和应用Java压缩库的机会。以下...
在IT行业中,文件压缩与解压缩是日常工作中常见的操作,特别是在数据传输、存储优化和软件分发等领域。这里我们主要探讨的是一个简单的工具类,它支持zip、rar、tar等多种格式的压缩和解压缩功能,并且经过实际测试...
在本篇文章中,我们将深入探讨如何使用C++来实现文件的压缩与解压缩功能。 首先,让我们了解一下文件I/O操作。在C++中,我们可以使用`fstream`库来处理文件的读写。例如,要读取一个文件,我们需要创建一个`...
在C#环境下实现哈夫曼编码的压缩与解压缩,可以帮助我们理解这一算法的工作原理,同时为文件处理提供了一个实用工具。 哈夫曼编码的核心思想是构建一棵哈夫曼树(Huffman Tree),这是一棵带权路径长度最短的二叉树...
JAVA文件压缩与解压缩实践(源代码).zipJAVA文件压缩与解压缩实践(源代码).zipJAVA文件压缩与解压缩实践(源代码).zipJAVA文件压缩与解压缩实践(源代码).zipJAVA文件压缩与解压缩实践(源代码).zipJAVA文件压缩与解压缩...
JAVA文件压缩与解压缩实践(源代码+论文) JAVA文件压缩与解压缩实践(源代码+论文) JAVA文件压缩与解压缩实践(源代码+论文) JAVA文件压缩与解压缩实践(源代码+论文) JAVA文件压缩与解压缩实践(源代码+论文) JAVA文件...
JAVA文件压缩与解压缩实践(源代码+LW)JAVA文件压缩与解压缩实践(源代码+LW)JAVA文件压缩与解压缩实践(源代码+LW)JAVA文件压缩与解压缩实践(源代码+LW)JAVA文件压缩与解压缩实践(源代码+LW)JAVA文件压缩与解压缩实践...
JAVA文件压缩与解压缩实践(源代码+论文)JAVA文件压缩与解压缩实践(源代码+论文)JAVA文件压缩与解压缩实践(源代码+论文)JAVA文件压缩与解压缩实践(源代码+论文)JAVA文件压缩与解压缩实践(源代码+论文)JAVA文件压缩与...
实际的PB压缩解压缩实现可能根据具体需求和设计有所不同,例如可能使用了特定的压缩库(如zlib或libarchive),或者采用了自定义的压缩算法。要深入了解这个话题,最好能够查看和分析提供的源代码。
JAVA文件压缩与解压缩实践(源代码+lw).rarJAVA文件压缩与解压缩实践(源代码+lw).rarJAVA文件压缩与解压缩实践(源代码+lw).rarJAVA文件压缩与解压缩实践(源代码+lw).rarJAVA文件压缩与解压缩实践(源代码+lw).rarJAVA...
**Zip压缩与解压缩** Zip是一种广泛使用的文件压缩格式,由菲尔·卡尔森在1989年开发,旨在减少文件占用的磁盘空间,提高数据传输效率。它通过使用不同的压缩算法,如DEFLATE,可以有效地缩小文件大小。在IT领域,...
(Java毕业设计)JAVA文件压缩与解压缩实践(Java毕业设计)JAVA文件压缩与解压缩实践(Java毕业设计)JAVA文件压缩与解压缩实践(Java毕业设计)JAVA文件压缩与解压缩实践(Java毕业设计)JAVA文件压缩与解压缩实践(Java毕业...
java毕业设计——java文件压缩与解压缩实践设计与开发(源代码+论文).zip java毕业设计——java文件压缩与解压缩实践设计与开发(源代码+论文).zip java毕业设计——java文件压缩与解压缩实践设计与开发(源代码+论文)....
在给定的标题“C++ 压缩解压缩库”中,我们可以推断这是一个针对C++语言的库,专注于文件或数据的压缩与解压缩功能。描述提到这是为VS2012版本编译的,意味着它可能使用了Visual Studio 2012的编译环境,并且库已经...
在"基于哈夫曼编码的文本文件压缩与解压缩"项目中,使用C语言实现这一过程。首先,我们需要分析文本文件中的字符频率,这通常通过遍历整个文本文件计算每个字符的出现次数来完成。接着,根据字符频率构建哈夫曼树。...