Java压缩与解压缩文件2
2008-09-22 20:08
435 查看
package com.yc.ycportal.ge.util;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
public class GZIPfile {
private boolean flag = true;
//定义一个接口,通过结构来调用该类的方法
public static GZIPfile getInterface(){
return new GZIPfile();
}
//创建一个方法,对文件进行解压缩
public boolean openFile(String InfileName,String OutfileName){
/**
* @InfileName 传入方法的文件名称及文件所在路径的具体值
* @OutfileName 对文件解压缩成功后,要将文件保存的具体位置和名称
* @return 返回类型为boolean,标识文件是否正常操作完成
*/
try {
GZIPInputStream gzip = new GZIPInputStream(new FileInputStream(InfileName));
FileOutputStream out = new FileOutputStream(OutfileName);
byte[] bt = new byte[1024];
int length = 0;
while((length=gzip.read(bt))>0){
out.write(bt, 0, length);
}
} catch (Exception e) {
this.flag = false;
System.out.println(e.getMessage());
}
return flag;
}
//创建一个方法对读取到的文件进行压缩处理
public boolean compFile(String InfileName,String OutfileName){
/**
* @InfileName 读入文件的具体名称和地址的值,对文件的数据进行压缩处理
* @OutfileName 读出的文件要存放的具体的地址和文件名称,处理后的压缩文件
* @return 返回一个boolean值表明程序是否能够争取的处理
*/
try {
GZIPOutputStream gzip = new GZIPOutputStream(new FileOutputStream(OutfileName));
FileInputStream in = new FileInputStream(InfileName);
byte[] bt = new byte[1024];
int length = 0;
while((length=in.read(bt))>0){
gzip.write(bt, 0, length);
}
} catch (Exception e) {
flag = false;
System.out.println(e.getMessage());
}
return flag;
}
public static void main(String args[]){
}
}
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
public class GZIPfile {
private boolean flag = true;
//定义一个接口,通过结构来调用该类的方法
public static GZIPfile getInterface(){
return new GZIPfile();
}
//创建一个方法,对文件进行解压缩
public boolean openFile(String InfileName,String OutfileName){
/**
* @InfileName 传入方法的文件名称及文件所在路径的具体值
* @OutfileName 对文件解压缩成功后,要将文件保存的具体位置和名称
* @return 返回类型为boolean,标识文件是否正常操作完成
*/
try {
GZIPInputStream gzip = new GZIPInputStream(new FileInputStream(InfileName));
FileOutputStream out = new FileOutputStream(OutfileName);
byte[] bt = new byte[1024];
int length = 0;
while((length=gzip.read(bt))>0){
out.write(bt, 0, length);
}
} catch (Exception e) {
this.flag = false;
System.out.println(e.getMessage());
}
return flag;
}
//创建一个方法对读取到的文件进行压缩处理
public boolean compFile(String InfileName,String OutfileName){
/**
* @InfileName 读入文件的具体名称和地址的值,对文件的数据进行压缩处理
* @OutfileName 读出的文件要存放的具体的地址和文件名称,处理后的压缩文件
* @return 返回一个boolean值表明程序是否能够争取的处理
*/
try {
GZIPOutputStream gzip = new GZIPOutputStream(new FileOutputStream(OutfileName));
FileInputStream in = new FileInputStream(InfileName);
byte[] bt = new byte[1024];
int length = 0;
while((length=in.read(bt))>0){
gzip.write(bt, 0, length);
}
} catch (Exception e) {
flag = false;
System.out.println(e.getMessage());
}
return flag;
}
public static void main(String args[]){
}
}
相关文章推荐
- JAVA 实现压缩与解压缩 rar和zip格式的文件
- Java ZIP文件压缩与解压缩
- Java 解压缩 zip格式的压缩文件
- java解压缩/压缩/加密压缩/加密解压缩 ZIP4J---ZIP文件压缩与解压缩学习
- Java小程序之哈夫曼树与文件压缩和解压缩(一)哈夫曼树构造篇
- Java实现对文件做压缩和解压缩(一般用于文件批量导入导出)
- 使用java.util.zip包压缩和解压缩文件
- java压缩与解压缩文件(利用apache的ant.jar)
- java ZipOutputStream压缩文件,ZipInputStream解压缩
- Java zip/gzip文件压缩和解压缩
- java压缩/解压缩zip格式文件
- Java压缩/解压缩二进制文件--http中content-encoding:deflate也可以使用
- java实现单个或多个文件的压缩、解压缩 支持zip、rar等格式
- java实现压缩、解压缩文件
- java压缩与解压缩文件(利用apache的ant.jar)
- java解压缩zip文件,java创建zip文件,java压缩文件,java解压文件,用到ant.jar解决汉字乱码
- java压缩/解压缩zip格式文件
- java压缩与解压缩文件(利用apache的ant.jar)
- Java用ZIP格式压缩和解压缩文件
- java解压缩zip文件,java创建zip文件,java压缩文件,java解压文件,用到ant.jar解决汉字乱码