Java压缩类库的使用 3.Apache Ant中的打包、压缩类库
inkfish原创,请勿商业性质转载,转载请注明来源(http://blog.csdn.net/inkfish)。
这里需要关注的是BZIP2格式,经过测试,总是无法正确压缩,原因未知,而apache commons bzip2格式的文件压缩正常。(来源:http://blog.csdn.net/inkfish)
Ant ZIP压缩:(来源:http://blog.csdn.net/inkfish)
package study.inkfish.compress;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Enumeration;
import org.apache.commons.io.IOUtils;
import org.apache.tools.zip.ZipEntry;
import org.apache.tools.zip.ZipFile;
import org.apache.tools.zip.ZipOutputStream;
public class AntZipCompress extends Compress {
@Override
protected void doCompress(File srcFile, File destFile) throws IOException {
ZipOutputStream zout = null;
InputStream is = null;
try {
is = new BufferedInputStream(new FileInputStream(srcFile), bufferLen);
zout = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(destFile), bufferLen));
zout.putNextEntry(new ZipEntry(srcFile.getName()));
IOUtils.copy(is, zout);
zout.closeEntry();
} finally {
IOUtils.closeQuietly(is);
IOUtils.closeQuietly(zout);
}
}
@Override
protected void doDecompress(File srcFile, File destDir) throws IOException {
ZipFile zipFile = new ZipFile(srcFile);
try {
@SuppressWarnings("unchecked")
Enumeration<ZipEntry> enums = zipFile.getEntries();
while (enums.hasMoreElements()) {
ZipEntry entry = enums.nextElement();
InputStream is = new BufferedInputStream(zipFile.getInputStream(entry), bufferLen);
OutputStream os = null;
try {
os = new BufferedOutputStream(new FileOutputStream(new File(destDir, entry.getName())), bufferLen);
IOUtils.copy(is, os);
} finally {
IOUtils.closeQuietly(is);
IOUtils.clo
相关文档:
如何读取资源文件:
(一)
Properties props = new Properties();
props.load(new FileInputStream("db.properties"));
(二)
blog.properties文件如下
dbdriver=oracle.jdbc.driver.OracleDriver
dburl=jdbc:oracle:thin:@127.0.0.1:1521:ora92
dbuser=blog
dbpwd=blog
- ......
在一个面向对象的系统中,系统的各种功能是由许许多多的不同对象协作完成的。在这种情况下,各个对象内部是如何实现自己的对系统设计人员来讲就不那么重要
了;而各个对象之间的协作关系则成为系统设计的关键。小到不同类之间的通信,大到各模块之间的交互,在系统设计之初都是要着重考虑的,这也是系统设计的主
要 ......
SCJP5学习笔记
一、定义线程
1、扩展java.lang.Thread类。
此类中有个run()方法,应该注意其用法:
public void run
()
如果该线程是使用独立的 Runnable
运行对象构造的,则调用该 Runnable
对象的 run
方法;否则,该方法不执行任何操作并返回。
Thread
的子类应 ......
为什么使用volatile比同步代价更低?
同步的代价, 主要由其覆盖范围决定, 如果可以降低同步的覆盖范围, 则可以大幅提升程序性能.
而volatile的覆盖范围仅仅变量级别的. 因此它的同步代价很低.
volatile原理是什么?
volatile的语义, 其实是告诉处理器, 不要将我放入工作内存, 请直接在主存操作我.(工作内存详见j ......