0

I did this question and I saw that exist a constructor of ZipInputStream called:

ZipInputStream(BufferedInputStream, Charset)

but the debugger throws me the error:

ZipInputStream(BufferedInputStream, Charset) is undefined

and give me the advice:

remove the argument to match ZipInputStream(InputStream)

I have installed the latest JDK and JRE 7 but I still have the same error.

Finally I solved the problem here:

Extracting file with ZipInputStream error UTFDataFormatException

Community
  • 1
  • 1
ƒernando Valle
  • 3,634
  • 6
  • 36
  • 58
  • Looks like you hove imported different classes. Make sure that you have imported `java.nio.charset.Charset` – Jens Jul 02 '14 at 07:23

2 Answers2

1

If you programm an android app you're using the android libraries. The android ZipInputStream has no public constructor with signature ZipInputStream(InputStream, Charset). It doesn't matter what JDK or JRE you install on your PC, since you're app will not run on the PC (or on the PC but in an emulator).

fabian
  • 80,457
  • 12
  • 86
  • 114
  • And there is an alternative? I have files in my zip with special characters. – ƒernando Valle Jul 02 '14 at 07:33
  • @ƒernandoValle: I don't have much experience with java / android and charsets but it looks like [InputStreamReader](http://developer.android.com/reference/java/io/InputStreamReader.html#InputStreamReader%28java.io.InputStream,%20java.lang.String%29) with the ZipInputStream as constructor parameter could do the trick. – fabian Jul 02 '14 at 07:42
  • 1
    @fabian - I doubt it. The Charset is specifying the encoding for ZipEntry names, not the files themselves. – Stephen C Jul 02 '14 at 08:01
  • I solved finally here using an external library http://stackoverflow.com/questions/24509264/extracting-file-with-zipinputstream-error-utfdataformatexception – ƒernando Valle Jul 02 '14 at 10:26
1

Apparently, there is no alternative in the Android API. However, if you can arrange that the ZIP file has the "Language encoding flag (EFS)" bit set, then a recent version of android should respect it, and thread the entry names as UTF-8 encoded.

Note that the 2nd ZipInputStream constructor was added to the (real) Java class libraries in Java 7, and the Android APIs are based on Java 6.

Reference:

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • How I set the EFS flag to a zip file using for example 7zip or other compressor? I have search about it but I didn't find a lot. – ƒernando Valle Jul 02 '14 at 08:12
  • thanks finally I solve my problem here http://stackoverflow.com/questions/24509264/extracting-file-with-zipinputstream-error-utfdataformatexception – ƒernando Valle Jul 02 '14 at 10:09