Japanese filename is getting garbled while extracting

2.4k Views Asked by At

I am zipping a .csv file as follows:

fileInputStream = new FileInputStream(csvFile);
final ZipEntry zipEntry = new ZipEntry(csvFile.getname());
            zipOutputStream.putNextEntry(zipEntry);
            final byte[] buffer = new byte[4 * 1024];
            int size = fileInputStream.read(buffer);
            while (size != -1) 
        {
                zipOutputStream.write(buffer, 0, size);
                size = fileInputStream.read(buffer);
        }       

The filename also contains japanese/chinese characters On extracting with winzip/ 7-zip the extracted .csv file name is not garbled but when default windows extracter is used the filename is garbled.

1

There are 1 best solutions below

0
appy On BEST ANSWER

I had used :

String fileName = MimeUtility.encodeText(filename,"SJIS",null);

and then it seemed to work fine on systems where the default language was japanese.