I use the following method to compress a file into a zip file:
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(); } } }
My problem is that I have flat text files with the contents of N°TICKET , for example, the encrypted result gives some numbered characters with an uncompressed N° TICKET . Symbols such as é and à also not supported.
I assume this is due to character encoding, but I don't know how to set it in my zip method on ISO-8859-1 ?
(I am running on windows 7, java 6)
source share