Incorrect symbols after file archiving



  • UTF-8 reference file. We need to create a zip archive. Archiving like that:

    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 an archived xml is opened in a text editor (e.g. notepad++) the non-correct, e.g.: <Вх_ВЗЛ:xd0?сточникДанных>ЗЛ</Вх_ВЗЛ:xd0?сточникДанных>i.e., instead of "I" undeclared symbols

    How to fix it.



  • Try this:

    zos.setEncoding("UTF-8");
    zos.setFallbackToUTF8(true); // для неизвестных симовлов
    zos.setUseLanguageEncodingFlag(true);                               
    zos.setCreateUnicodeExtraFields(ZipArchiveOutputStream.UnicodeExtraFieldPolicy.ALWAYS);
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2