Using ANT to extract the compressed file containing the Chinese file name

xiaoxiao2021-03-06  21

Chinese issues are universality issues in Java. This afternoon encounters a compressed file decompression problem containing Chinese file names. It has been found. It is existing.

In the java.util.zip package can also be used to process the decompression problem, but the compression package containing the Chinese file name is powerful, because ZipOutputStream compression and decompression zip files are processed in UTF-8 encoding, And we use WinZip compressed files to handle the file name only in ASCII coding. So there is an inconsistency of encoding.

There are two solutions:

The first is to modify zipoutputstream, refer to the modification as follows: (I have not tested this)

// Zipentry E = CreateZipentry (GetF8String (B, 0, LEN));

ZIPENTRY E = NULL;

Try {

IF (this.encoding.touppercase (). Equals ("UTF-8"))

E = CREATEZIPENTRY (GetF8String (B, 0, LEN));

Else

E = CREATEZIPENTRY (New String (B, 0, Len, this.Encoding);

}

Catch (Exception Bytee) {

E = CREATEZIPENTRY (GetF8String (B, 0, LEN));

}

Plus one more

Public ZipinputStream (InputStream IN, String Encoding) {

Super (New PushbackInputStream (in, 512), New INFLATER (TRUE), 512)

Usesdefaultinflater = true;

IF (in == NULL) {

Throw New NullPointerException ("in is null");

}

THIS.ENCODING = Encoding;

}

The second method is to use the ANT package, you can download the official website http://ant.cgi, import Ant.jar into the class.

Reference, for example,:

Public void unzip (string zipfilename, string outputdirectory) throws exception {

Try {

Org.apache.tools.zip.zipfile zipfile = new org.apache.tools.zip.zipfile (zipfilename);

Java.util.enumeration e = zipfile.getentries ();

Org.apache.tools.zip.zipentry zipentry = NULL;

While (E.haASMoreElements ()) {

ZIPENTRY = (org.apache.tools.zip.zipentry) E.NEXTELEMENT ();

System.out.println ("unziping" zipentry.getname ());

IF (ZIPENTRY.ISDIRECTORY ()) {

String name = zipentry.getname ();

Name = name.substring (0, Name.length () - 1);

System.out.println ("Output Path: OutputDirectory File.seParetor Name);

File F1 = New File (OutputDirectory File.seParetor);

F1.mkdir ();

FILE F = New File (OutputDirectory File.seParetor Name);

F.mkdir (); System.out.println ("Create a directory:" OutputDirectory file.seParetor name);

} else {

File f = new file (OutputDirectory File.seParetor ZiPENTRY.GETNAME ());

F.createNewFile ();

InputStream in = zipfile.getinputStream (ZIPENTRY);

FileoutPutStream out = new fileoutputstream (f);

// -------- Solve the picture of the picture distortion

INT C;

Byte [] by = new byte [1024];

While (c = in.read (by))! = -1) {

Out.write (by, 0, c);

}

Out.close ();

In.Close ();

}

}

}

Catch (Exception EX) {

}

}

Summary: You can't do anything, but you can't use Google.

转载请注明原文地址:https://www.9cbs.com/read-43180.html

New Post(0)