[JAVA]

Beim Austausch von ZIP-Dateien bei der Arbeit war der ZIP-Ersteller ein Mac-Benutzer und dies war Windows. Wie Sie an dieser Stelle sehen können, ist der Eintragsname mit UTF-8 auf dem Mac ZIP-zertifiziert, und der Eintragsname wird in der japanischen Umgebung in der Windows-Standard-ZIP-Bereitstellung mit Windows-31j (Shift-JIS) erweitert. Ist verstümmelt. ~~ Ich verstehe immer noch nicht, was es bedeutet, mit Zeichencodes zu kämpfen. ~~ Es ist vorbei, wenn ich freie Software einbaue, die UTF-8 unterstützt. Da ich als ansässiger Kunde arbeite, kann ich es ohne Erlaubnis herunterladen, und da es eine große Sache ist, habe ich beschlossen, es selbst zu lösen.

Vorerst in Java bereitstellen

Referenz: http://www.ne.jp/asahi/hishidama/home/tech/java/zip.html Es wurde auf Mr. Hishidamas Stabilitätsseite fast gelöst. ..

ZipDecoder.java


import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.zip.ZipFile;

public class ZipDecoder {

	private static final String ZIP_FILE = "C:\\temp\\Ordner.zip";

	public static void main(String[] args) {
		decode(ZIP_FILE);
	}

	public static void decode(String strPath) {
		if (strPath == null || !strPath.toLowerCase().endsWith(".zip")) {
			System.out.println("Argument is not zip file.");
			return;
		}
		Path zipFilePath = Paths.get(strPath);
		String outDir = zipFilePath.toString().replace(".zip", "");
		if (Files.notExists(zipFilePath)) {
			System.out.println("Argument is not file path.");
			return;
		}
		try (ZipFile zipFile = new ZipFile(zipFilePath.toFile(), Charset.forName("UTF-8"))) {
			zipFile.stream().filter(entry -> !entry.isDirectory()).forEach(entry -> {
				Path outName = Paths.get(outDir, entry.getName());
				try {
					Files.createDirectories(outName.getParent());
				} catch (IOException e1) {
					throw new UncheckedIOException(e1);
				}
				try (InputStream is = zipFile.getInputStream(entry);
						BufferedOutputStream os = new BufferedOutputStream(Files.newOutputStream(outName))) {
					byte[] buf = new byte[1024];
					while (is.read(buf) >= 0) {
						os.write(buf);
					}
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			});

		} catch (IOException e) {
			throw new UncheckedIOException(e);
		}
	}
}

Wiederverwendung

Da der Austausch von ZIP-Dateien noch nicht abgeschlossen ist, werde ich sie neu erstellen, damit sie verwendet werden können. Übergeben Sie den Dateinamen als Startargument, damit er durch Ziehen und Ablegen erweitert werden kann. Es scheint, dass jar mithilfe von launch4j in eine exe-Datei umgewandelt werden kann, aber da es beim Kunden ansässig ist (

Referenz: https://qiita.com/bugtrap/items/15864474076767a7a957

ZipDecoder.java


import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.zip.ZipFile;

public class ZipDecoder {

	public static void main(String[] args) {
		if (args.length == 0) {
			System.out.println("There are no Arguments.");
		}
		Arrays.asList(args).stream().forEach(ZipDecoder::decode);
	}

	public static void decode(String strPath) {
		if (strPath == null || !strPath.toLowerCase().endsWith(".zip")) {
			System.out.println("Argument is not zip file.");
			return;
		}
		Path zipFilePath = Paths.get(strPath);
		String outDir = zipFilePath.toString().replace(".zip", "");
		if (Files.notExists(zipFilePath)) {
			System.out.println("Argument is not file path.");
			return;
		}
		try (ZipFile zipFile = new ZipFile(zipFilePath.toFile(), Charset.forName("UTF-8"))) {
			zipFile.stream().filter(entry -> !entry.isDirectory()).forEach(entry -> {
				Path outName = Paths.get(outDir, entry.getName());
				try {
					Files.createDirectories(outName.getParent());
				} catch (IOException e1) {
					throw new UncheckedIOException(e1);
				}
				try (InputStream is = zipFile.getInputStream(entry);
						BufferedOutputStream os = new BufferedOutputStream(Files.newOutputStream(outName))) {
					byte[] buf = new byte[1024];
					while (is.read(buf) >= 0) {
						os.write(buf);
					}
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			});

		} catch (IOException e) {
			throw new UncheckedIOException(e);
		}
	}
}

call-decoder.bat


@echo off

rem Befehlsprüfung
where java 2> nul > nul || goto :notfound

java -jar ZipDecoder.jar %*

Echo-Bereitstellung abgeschlossen
goto :end

:notfound
Setzen Sie den Befehl echo java in PATH
goto :end

:end
pause

Wählen Sie zwei Zip-Dateien aus und ziehen Sie sie per Drag & Drop in die Bat-Datei

image.png

Ich konnte es durch Ziehen und Ablegen erweitern.

image.png

Es ist schwierig, zwei Java-Dateien und eine Bat-Datei zu haben

Sie sollten eine Java-Datei in bat erstellen, kompilieren und verwenden, oder? Also habe ich es versucht.

decord.bat


@echo off

rem Befehlsprüfung
where java 2> nul > nul || goto :notfound

echo import java.io.BufferedOutputStream;                                                                         > ZipDecoder.java
echo import java.io.IOException;                                                                                  >> ZipDecoder.java
echo import java.io.InputStream;                                                                                  >> ZipDecoder.java
echo import java.io.UncheckedIOException;                                                                         >> ZipDecoder.java
echo import java.nio.charset.Charset;                                                                             >> ZipDecoder.java
echo import java.nio.file.Files;                                                                                  >> ZipDecoder.java
echo import java.nio.file.Path;                                                                                   >> ZipDecoder.java
echo import java.nio.file.Paths;                                                                                  >> ZipDecoder.java
echo import java.util.Arrays;                                                                                     >> ZipDecoder.java
echo import java.util.zip.ZipFile;                                                                                >> ZipDecoder.java
echo public class ZipDecoder {                                                                                    >> ZipDecoder.java
echo 	public static void main(String[] args) {                                                                  >> ZipDecoder.java
echo 		if (args.length == 0) {                                                                               >> ZipDecoder.java
echo 			System.out.println("There are no Arguments.");                                                    >> ZipDecoder.java
echo 		}                                                                                                     >> ZipDecoder.java
echo 		Arrays.asList(args).stream().forEach(ZipDecoder::decode);                                             >> ZipDecoder.java
echo 	}                                                                                                         >> ZipDecoder.java
echo 	public static void decode(String strPath) {                                                               >> ZipDecoder.java
echo 		if (strPath == null ^|^| !strPath.toLowerCase().endsWith(".zip")) {                                     >> ZipDecoder.java
echo 			System.out.println("Argument is not zip file.");                                                  >> ZipDecoder.java
echo 			return;                                                                                           >> ZipDecoder.java
echo 		}                                                                                                     >> ZipDecoder.java
echo 		Path zipFilePath = Paths.get(strPath);                                                                >> ZipDecoder.java
echo 		String outDir = zipFilePath.toString().replace(".zip", "");                                           >> ZipDecoder.java
echo 		if (Files.notExists(zipFilePath)) {                                                                   >> ZipDecoder.java
echo 			System.out.println("Argument is not file path.");                                                 >> ZipDecoder.java
echo 			return;                                                                                           >> ZipDecoder.java
echo 		}                                                                                                     >> ZipDecoder.java
echo 		try (ZipFile zipFile = new ZipFile(zipFilePath.toFile(), Charset.forName("UTF-8"))) {                 >> ZipDecoder.java
echo 			zipFile.stream().filter(entry -^> !entry.isDirectory()).forEach(entry -^> {                         >> ZipDecoder.java
echo 				Path outName = Paths.get(outDir, entry.getName());                                            >> ZipDecoder.java
echo 				try {                                                                                         >> ZipDecoder.java
echo 					Files.createDirectories(outName.getParent());                                             >> ZipDecoder.java
echo 				} catch (IOException e1) {                                                                    >> ZipDecoder.java
echo 					throw new UncheckedIOException(e1);                                                       >> ZipDecoder.java
echo 				}                                                                                             >> ZipDecoder.java
echo 				try (InputStream is = zipFile.getInputStream(entry);                                          >> ZipDecoder.java
echo 						BufferedOutputStream os = new BufferedOutputStream(Files.newOutputStream(outName))) { >> ZipDecoder.java
echo 					byte[] buf = new byte[1024];                                                              >> ZipDecoder.java
echo 					while (is.read(buf) ^>= 0) {                                                               >> ZipDecoder.java
echo 						os.write(buf);                                                                        >> ZipDecoder.java
echo 					}                                                                                         >> ZipDecoder.java
echo 				} catch (IOException e) {                                                                     >> ZipDecoder.java
echo 					throw new UncheckedIOException(e);                                                        >> ZipDecoder.java
echo 				}                                                                                             >> ZipDecoder.java
echo 			});                                                                                               >> ZipDecoder.java
echo 		} catch (IOException e) {                                                                             >> ZipDecoder.java
echo 			throw new UncheckedIOException(e);                                                                >> ZipDecoder.java
echo 		}                                                                                                     >> ZipDecoder.java
echo 	}                                                                                                         >> ZipDecoder.java
echo }                                                                                                            >> ZipDecoder.java

javac ZipDecoder.java

java ZipDecoder %*

del ZipDecoder.java
del ZipDecoder.class

Echo-Bereitstellung abgeschlossen
goto :end

:notfound
Setzen Sie den Befehl echo java in PATH
goto :end

:end
pause

Nachdem ich einigen Symbolen entkommen war, konnte ich normal ausgeben.

image.png

Zip-Datei ziehen und ablegen

image.png

Ich konnte es bereitstellen.

Ergänzung

Diese Quelle kann verwendet werden, wenn der Pfad Java8 oder höher ist.

Recommended Posts