Android: read a GZIP file in the ASSETS folder

Tawani picture Tawani · Mar 2, 2010 · Viewed 14.3k times · Source

How can you read GZIP file in Android located in the "ASSETS" (or resources/raw) folder?

I have tried the following code, but my stream size is always 1.

GZIPInputStream fIn = new GZIPInputStream(mContext.getResources().openRawResource(R.raw.myfilegz)); 
int size = fIn.available();

for some reason the size is always 1. But if Idon't GZIP the file, it works fine.

NOTE: Using Android 1.5

Answer

Cuper Hector picture Cuper Hector · Aug 10, 2010

I met the same problem when reading a gz file from assets folder.

It's caused by the file name of the gz file. Just renaming yourfile.gz to other name like yourfile.bin. It seems Android build system would decompress a file automatically if it thought it's a gz.