0

I have a problem with files with a Unicode name in Zip. I am using vjslib.dll. in a normal scenario, it's working perfect but when I am trying to zip file which has a Unicode character name like "サンプルファイル.pdf"it's represented as a "???????.pdf", in zip file while extracting a zip file Unicode file name nane represent as a "_______.pdf" is there any way to generate a zip with the exact name of the file does not matter file name in English or another language

zipFileName = "c:\SampleZip\myfile.zip"

sourceFile

  1. c:\sample\サンプルファイル.pdf
  2. c:\sample\отличается.xml

    private void Zip(string zipFileName, string[] sourceFile)
    {
        FileOutputStream filOpStrm = new FileOutputStream(zipFileName);
        ZipOutputStream zipOpStrm = new ZipOutputStream(filOpStrm);
        FileInputStream filIpStrm = null;
    
        foreach (string strFilName in sourceFile)
        {
            filIpStrm = new FileInputStream(strFilName);
            ZipEntry ze = new ZipEntry(Path.GetFileName(strFilName));
            zipOpStrm.putNextEntry(ze);
            sbyte[] buffer = new sbyte[1024];
            int len = 0;
    
            while ((len = filIpStrm.read(buffer)) >= 0)
            {
                zipOpStrm.write(buffer, 0, len);
            }
        }
    
        zipOpStrm.closeEntry();
        filIpStrm.close();
        zipOpStrm.close();
        filOpStrm.close();
    }
    
Chirag
  • 375
  • 4
  • 30
  • First, it is bad practice to use `Close()` with your streams the way you did here. Wrap the streams with `using` statements instead (https://stackoverflow.com/questions/75401/what-are-the-uses-of-using-in-c-sharp). Second, i assume you use SharpZipLib. You should be able to enable Unicode support (more accurately UTF-8 support) for each ZipEntry individually by setting its `ZipEntry.IsUnicodeText` property to _true_. –  Sep 20 '18 at 15:08
  • vjslib.dll is old, being able to only use 8-bit encoding for names was an old .zip format restriction. Lots of shiny new zip libraries around. – Hans Passant Sep 20 '18 at 15:17

0 Answers0