UTF-8 source file. Need to create a zip archive. Archiving as follows:
FileInputStream byteArrayInputStream = new FileInputStream("C:\\input.xml"); byte[] buffer = new byte[1024]; FileOutputStream baos = new FileOutputStream("C:\\output.xml"); ZipArchiveOutputStream zos = new ZipArchiveOutputStream(baos); ZipArchiveEntry ze = new ZipArchiveEntry(fileName); zos.putArchiveEntry(ze); InputStream in = byteArrayInputStream; int len; while ((len = in.read(buffer)) > 0) zos.write(buffer, 0, len); in.close(); zos.closeArchiveEntry(); zos.close(); baos.close(); byteArrayInputStream.close();
When you open an archived xml in a text editor (for example, notepad ++), incorrect content is opened, for example: <Вх_ВЗЛ:xd0?сточникДанных>ЗЛ</Вх_ВЗЛ:xd0?сточникДанных>
i.e. instead of "and" incomprehensible characters
How to fix it
ZipArchiveOutputStream
creates a .zip file, i.e. The archive (it can be opened with a guide or archiver) containing theZipArchiveEntry
file (with the name fromfileName
) is not very clear why you save it as .xml, and how you open it.D0
is the first byte "And" in utf-8, the second byte is there98
. Is the source file normal? The feeling that someone is reading the file in blocks of N bytes, recodes the block, and pastes the results, so when a multibyte character hits the block boundary, it turns out to be garbage. - zRrr