Chinese issues in Java understand the compressed zip

xiaoxiao2021-03-06  85

During this time, I solve the problem of interpressing Chinese, but for Chinese compressed files, I always have a lot of posts. I found that many people have encountered this situation. I just solved this problem, so I mentioned, I hope to have you Helped. (Say, I see a lot of answers, I don't necessarily test this code, just have the code before, and stick to it, and still very deep, I don't know a lot of questions. Take the test with your code, the result is a lot of time, so I hope some people should not just think about some of the posts to stick to the previous post), say more, and more. With the ZIP class comes with Java, I didn't realize the problem of solving the Chinese problem. I don't know if my method is wrong, but I have currently adopted ant.jar, using this JAR file, indeed unpacking Chinese issues. I put this JAR file on my machine. You can download ftp://202.97.215.161 user: zypass: 1234 first anti-virus, my machine has not anticinked for a few days. The source code of this JAR packet is quoted as follows: package com.highcom.hcgip.basic.unzip;

/ ** *

Title: GIP3.1 Javadoc *

Description: Use ORG.Apache.Tools.zip to solve the Chinese name error *

CopyRight : CopyRight (C) 2004 *

Company: * @Author zy * @version 1.0 * /

Import java.util. *; import java.util.zip. *; import java.io. *;

Public class tryunzip {public tryunzip () {}

/ ** * * Decompression processing * @Param ZipFileName To make compression processing files (D: //aa.zip ") * @Param OutputDirectory compressed file path (d: //) * / 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.hasMoreElements ()) {zipentry = (org.apache.tools.zip.zipentry) E.NEXTELEMENT (); System.out.Println ("unziping" zipentry.getname ()); if (Zipentry.Indirectory ()) {String name = zipentry.getName (); name = name.substring (0, name.Length () - 1); system.out.println ("Output path:" OutputDirectory file.separator name) FILE F = New File (OutputDirectory File.seParator Name); F.mkdir (); System.out.Println ("Created Directory:" OutputDirectory File.seParetor Name);} else {file f = new File (outputDirectory File.separator zipEntry.getName ()); f.createNewFile (); InputStream in = zipFile.getInputStream (zipEntry); FileOutputStream out = new FileOutputStream (f); // -------- Solved 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) {

}

}

Public static void main (string [] args) {TRY {Tryunzip test = new tryunzip (); test.unzip ("e: //ok.zip", "e: //");} catch (exception e) { E.PrintStackTrace (System.out);}}

}

Description: 1. Since I have a break tomorrow, I may not be able to open, so people who want to come to those who have not discovered. It must be zip compressed files, Rar can't, and currently only support this compressed format ok.zip ----- Test .txt ----- 78.jpg, this is not supported (it is a file under the compressed file) The clip, the folder contains the corresponding compressed file, I have time I am doing) ok.zip ---- TEST / Test .txt ----- Test / 78.jpg

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

New Post(0)