菜鸟学习java,求大神解释下面的代码各段是什么意思,尽量详细,谢谢
UnZip2.javaimportjava.io.*;importjava.util.*;importjava.util.zip.*;publicclassUnZip2{...
UnZip2.java
import java.io.*;
import java.util.*;
import java.util.zip.*;
public class UnZip2 {
static final int BUFFER = 2048;
public static void main (Stringargv[]) {
try {
BufferedOutputStream dest =null;
BufferedInputStream is =null;
ZipEntry entry;
ZipFile zipfile = newZipFile(argv[0]);
Enumeration e =zipfile.entries();
while(e.hasMoreElements()){
entry = (ZipEntry)e.nextElement();
System.out.println("Extracting: " +entry);
is = new BufferedInputStream
(zipfile.getInputStream(entry));
int count;
byte data[] = newbyte[BUFFER];
FileOutputStream fos =new
FileOutputStream(entry.getName());
dest = new
BufferedOutputStream(fos,BUFFER);
while ((count =is.read(data, 0, BUFFER))
!= -1) {
dest.write(data, 0,count);
}
dest.flush();
dest.close();
is.close();
}
} catch(Exception e) {
e.printStackTrace();
}
}
} 展开
import java.io.*;
import java.util.*;
import java.util.zip.*;
public class UnZip2 {
static final int BUFFER = 2048;
public static void main (Stringargv[]) {
try {
BufferedOutputStream dest =null;
BufferedInputStream is =null;
ZipEntry entry;
ZipFile zipfile = newZipFile(argv[0]);
Enumeration e =zipfile.entries();
while(e.hasMoreElements()){
entry = (ZipEntry)e.nextElement();
System.out.println("Extracting: " +entry);
is = new BufferedInputStream
(zipfile.getInputStream(entry));
int count;
byte data[] = newbyte[BUFFER];
FileOutputStream fos =new
FileOutputStream(entry.getName());
dest = new
BufferedOutputStream(fos,BUFFER);
while ((count =is.read(data, 0, BUFFER))
!= -1) {
dest.write(data, 0,count);
}
dest.flush();
dest.close();
is.close();
}
} catch(Exception e) {
e.printStackTrace();
}
}
} 展开
3个回答
展开全部
UnZip2.java //文件位置
import java.io.*;
import java.util.*;
import java.util.zip.*; //引入的包
public class UnZip2 { //类名
static final int BUFFER = 2048; //定义一次最大读入的字节数
public static void main (Stringargv[]) {//主函数
try {
BufferedOutputStream dest =null; //定义输出的字节流变量
BufferedInputStream is =null; //定义输入字节流变量
ZipEntry entry; //定义压缩类中的对象
ZipFile zipfile = newZipFile(argv[0]); //输入压缩路径+文件名
Enumeration e =zipfile.entries(); //创建获取压缩数据对象
while(e.hasMoreElements()){ //循环获取待压缩数据
entry = (ZipEntry)e.nextElement(); //获取下一个读入信息
System.out.println("Extracting: " +entry); //打印压缩信息
is = new BufferedInputStream //创建输入字节流对象
(zipfile.getInputStream(entry)); //并读入数据
int count;
byte data[] = newbyte[BUFFER]; //创建接收数据字节 定义最大字节数是上面定义的全局常量2048
FileOutputStream fos =new
FileOutputStream(entry.getName()); // 获取传入数据的目标
dest = new
BufferedOutputStream(fos,BUFFER);
while ((count =is.read(data, 0, BUFFER)) //循环读入直到读完
!= -1) {
dest.write(data, 0,count); //如果未读完数据则写入
}
dest.flush();
dest.close();
is.close(); //关闭字节流写入(每次应用字节流后必做操作)
}
} catch(Exception e) {
e.printStackTrace(); //如果出现异常则抓取
}
}
}
import java.io.*;
import java.util.*;
import java.util.zip.*; //引入的包
public class UnZip2 { //类名
static final int BUFFER = 2048; //定义一次最大读入的字节数
public static void main (Stringargv[]) {//主函数
try {
BufferedOutputStream dest =null; //定义输出的字节流变量
BufferedInputStream is =null; //定义输入字节流变量
ZipEntry entry; //定义压缩类中的对象
ZipFile zipfile = newZipFile(argv[0]); //输入压缩路径+文件名
Enumeration e =zipfile.entries(); //创建获取压缩数据对象
while(e.hasMoreElements()){ //循环获取待压缩数据
entry = (ZipEntry)e.nextElement(); //获取下一个读入信息
System.out.println("Extracting: " +entry); //打印压缩信息
is = new BufferedInputStream //创建输入字节流对象
(zipfile.getInputStream(entry)); //并读入数据
int count;
byte data[] = newbyte[BUFFER]; //创建接收数据字节 定义最大字节数是上面定义的全局常量2048
FileOutputStream fos =new
FileOutputStream(entry.getName()); // 获取传入数据的目标
dest = new
BufferedOutputStream(fos,BUFFER);
while ((count =is.read(data, 0, BUFFER)) //循环读入直到读完
!= -1) {
dest.write(data, 0,count); //如果未读完数据则写入
}
dest.flush();
dest.close();
is.close(); //关闭字节流写入(每次应用字节流后必做操作)
}
} catch(Exception e) {
e.printStackTrace(); //如果出现异常则抓取
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询