今天在写一套解压文件的东西遇到一个问题就是解压太慢,后来发现在
{
File file= new File(strZipPath+strZipFile);
FileInputStream f = new FileInputStream(file);
ZipInputStream in = new ZipInputStream(new DataInputStream(f));
System.out.println( "Writing file " + strSourceFilePath+strSourceFile);
DataOutputStream out =new DataOutputStream(new FileOutputStream(strSourceFilePath+strSourceFile));
in.getNextEntry();
int c;
System.out.println(System.currentTimeMillis()+"开始解压");
while((c = in.read()) != -1){
out.write(c);
}
in.close();
out.close();
标红的代表每次读取一个字符就是这里出现了问题,解决办法如下
{
File file= new File(strZipPath+strZipFile);
FileInputStream f = new FileInputStream(file);
ZipInputStream in = new ZipInputStream(new DataInputStream(f));
System.out.println( "Writing file " + strSourceFilePath+strSourceFile);
DataOutputStream out =new DataOutputStream(new FileOutputStream(strSourceFilePath+strSourceFile));
in.getNextEntry();
int c;
byte[] input = new byte[256];
System.out.println(System.currentTimeMillis()+"开始解压");
while((c = in.read(input)) != -1){
out.write(c);
}
in.close();
out.close();
立马见效,很快了