Java Zip Character Encoding
Ich verwende die folgende Methode, um eine Datei in eine ZIP-Datei zu komprimieren:
import java.util.zip.CRC32;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
public static void doZip(final File inputfis, final File outputfis) throws IOException {
FileInputStream fis = null;
FileOutputStream fos = null;
final CRC32 crc = new CRC32();
crc.reset();
try {
fis = new FileInputStream(inputfis);
fos = new FileOutputStream(outputfis);
final ZipOutputStream zos = new ZipOutputStream(fos);
zos.setLevel(6);
final ZipEntry ze = new ZipEntry(inputfis.getName());
zos.putNextEntry(ze);
final int BUFSIZ = 8192;
final byte inbuf[] = new byte[BUFSIZ];
int n;
while ((n = fis.read(inbuf)) != -1) {
zos.write(inbuf, 0, n);
crc.update(inbuf);
}
ze.setCrc(crc.getValue());
zos.finish();
zos.close();
} catch (final IOException e) {
throw e;
} finally {
if (fis != null) {
fis.close();
}
if (fos != null) {
fos.close();
}
}
}
Mein Problem ist, dass ich flache Textdateien mit dem Inhalt habeN°TICKET
Das komprimierte Ergebnis gibt beispielsweise einige ungewöhnliche Zeichen aus, wenn es nicht komprimiert istN° TICKET
. Auch Zeichen wieé
undà
werden nicht unterstützt.
Ich vermute, es liegt an der Zeichenkodierung, aber ich weiß nicht, wie ich sie in meiner zip-Methode einstellen sollISO-8859-1
?
(Ich laufe auf Windows 7, Java 6)