-
Bug
-
Resolution: Fixed
-
P4
-
1.4.0
-
b57
-
x86
-
windows_98
Name: nt126004 Date: 11/27/2001
java version "1.4.0-beta3"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta3-b84)
Java HotSpot(TM) Client VM (build 1.4.0-beta3-b84, mixed mode)
java.until.zip.ZipFile or ZipInputStream can't unzip file(unicode name) in zip
by winzip8.0
source code:
import java.util.zip.*;
import java.io.*;
public class UnzipF {
private String filename;
public UnzipF(String filename){
this.filename = filename;
}
public boolean unzip(){
try {
String topdir = filename.substring(0,filename.indexOf(".zip"));
if (!(new java.io.File(topdir)).mkdir()) System.out.println("topdir of
filename can't created!");
ZipInputStream in = new ZipInputStream(new FileReader(filename));
//ZipInputStream in = new ZipInputStream(new DataInputStream(new
java.io.FileInputStream(filename)));
ZipEntry entry;
String entryname;
byte[] buf = new byte[4096];
int len,length;
String outFilename;
OutputStream out;
String dirname;
while ((entry = in.getNextEntry()) != null) {
entryname = entry.getName();
if (!entry.isDirectory()){
int index = entryname.lastIndexOf('/');
if(index != -1){
dirname = entryname.substring(0,index+1);
if (!(new java.io.File(topdir+'/'+dirname)).exists()) (new
java.io.File(topdir+'/'+dirname)).mkdirs() ;
}
outFilename = topdir + '/' + entryname;
out = new java.io.FileOutputStream(outFilename);
length = 0 ;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
length=length+len;
}
out.close();
System.out.print("outFilename:"+outFilename);
System.out.println(" length:"+length);
//System.in.read();
}
else {
if (!(new java.io.File(topdir+'/'+entryname)).exists()) (new
java.io.File(topdir+'/'+entryname)).mkdirs() ;
System.out.println("topdir+'/'+entryname:"+topdir+'/'+entryname);
}
}
in.close();
return true;
} catch (IOException e) {
System.out.println("test");
System.out.println(e.getMessage());
return false;
}
}
public static void main(String args[]) {
UnzipF uf = new UnzipF(args[0]);
uf.unzip();
}
}
readme.zip's entry(zip by winzip8.0):
复件 readme.txt
readme.txt
commad:java UnzipF readme.zip
Exception:
Exception in thread "main" java.lang.IllegalArgumentException
at java.util.zip.ZipInputStream.getUTF8String(ZipInputStream.java:291)
at java.util.zip.ZipInputStream.readLOC(ZipInputStream.java:230)
at java.util.zip.ZipInputStream.getNextEntry(ZipInputStream.java:75)
at UnzipF.unzip(UnzipF.java:24)
at UnzipF.main(UnzipF.java:58)
(Review ID: 135772)
======================================================================
java version "1.4.0-beta3"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta3-b84)
Java HotSpot(TM) Client VM (build 1.4.0-beta3-b84, mixed mode)
java.until.zip.ZipFile or ZipInputStream can't unzip file(unicode name) in zip
by winzip8.0
source code:
import java.util.zip.*;
import java.io.*;
public class UnzipF {
private String filename;
public UnzipF(String filename){
this.filename = filename;
}
public boolean unzip(){
try {
String topdir = filename.substring(0,filename.indexOf(".zip"));
if (!(new java.io.File(topdir)).mkdir()) System.out.println("topdir of
filename can't created!");
ZipInputStream in = new ZipInputStream(new FileReader(filename));
//ZipInputStream in = new ZipInputStream(new DataInputStream(new
java.io.FileInputStream(filename)));
ZipEntry entry;
String entryname;
byte[] buf = new byte[4096];
int len,length;
String outFilename;
OutputStream out;
String dirname;
while ((entry = in.getNextEntry()) != null) {
entryname = entry.getName();
if (!entry.isDirectory()){
int index = entryname.lastIndexOf('/');
if(index != -1){
dirname = entryname.substring(0,index+1);
if (!(new java.io.File(topdir+'/'+dirname)).exists()) (new
java.io.File(topdir+'/'+dirname)).mkdirs() ;
}
outFilename = topdir + '/' + entryname;
out = new java.io.FileOutputStream(outFilename);
length = 0 ;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
length=length+len;
}
out.close();
System.out.print("outFilename:"+outFilename);
System.out.println(" length:"+length);
//System.in.read();
}
else {
if (!(new java.io.File(topdir+'/'+entryname)).exists()) (new
java.io.File(topdir+'/'+entryname)).mkdirs() ;
System.out.println("topdir+'/'+entryname:"+topdir+'/'+entryname);
}
}
in.close();
return true;
} catch (IOException e) {
System.out.println("test");
System.out.println(e.getMessage());
return false;
}
}
public static void main(String args[]) {
UnzipF uf = new UnzipF(args[0]);
uf.unzip();
}
}
readme.zip's entry(zip by winzip8.0):
复件 readme.txt
readme.txt
commad:java UnzipF readme.zip
Exception:
Exception in thread "main" java.lang.IllegalArgumentException
at java.util.zip.ZipInputStream.getUTF8String(ZipInputStream.java:291)
at java.util.zip.ZipInputStream.readLOC(ZipInputStream.java:230)
at java.util.zip.ZipInputStream.getNextEntry(ZipInputStream.java:75)
at UnzipF.unzip(UnzipF.java:24)
at UnzipF.main(UnzipF.java:58)
(Review ID: 135772)
======================================================================
- relates to
-
JDK-4244499 ZipEntry() does not convert filenames from Unicode to platform
- Resolved