Duplicate :
|
Name: nt126004 Date: 05/21/2002 FULL PRODUCT VERSION : java version "1.4.0" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92) Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode) A DESCRIPTION OF THE PROBLEM : When I try to get an InputStream for a ZipEntry which has Korean characters in the filename, ZipFile.getInputStream returns null. The same code works fine for ZipEntries which do not have Korean characters. The Korean zip file utility AlZip.exe was used. See the below program. This bug can be reproduced always. ---------- BEGIN SOURCE ---------- import java.io.*; import java.util.*; import java.util.zip.*; public class ZipUnzip { public static final void copyInputStream(InputStream in, OutputStream out) throws IOException { byte[] buffer = new byte[1024]; int len; while((len = in.read(buffer)) >= 0) out.write(buffer, 0, len); in.close(); out.close(); } public static void unzip(String filename) { Enumeration entries; ZipFile zipFile; try { zipFile = new ZipFile(filename); entries = zipFile.entries(); while(entries.hasMoreElements()) { ZipEntry entry = (ZipEntry)entries.nextElement(); System.out.println("1. Name : " + entry.getName()); if(entry.isDirectory()) { // Assume directories are stored parents first then children. System.out.println("2. Name : " + entry.getName()); System.err.println("Extracting directory: " + entry.getName()); // This is not robust, just for demonstration purposes. (new File(entry.getName())).mkdir(); continue; } System.err.println("Extracting file: " + entry.getName()); //null for korean filenames, ok otherwise. InputStream in = zipFile.getInputStream(entry); if (in == null) System.out.println("ZipFile.getInputStream returned null"); else { copyInputStream(in, new BufferedOutputStream(new FileOutputStream(entry.getName()))); } } zipFile.close(); } catch (IOException ioe) { System.err.println("Unhandled exception:"); ioe.printStackTrace(); return; } } public static final void main(String[] args) { if(args.length != 1) { System.err.println("Usage: Unzip zipfile"); return; } unzip(args[0]); } } ---------- END SOURCE ---------- (Review ID: 146266) ======================================================================