public class ResLoader {
/**
* @param res
* @throws IOException
* @throws FileNotFoundException
* @throws IOException
*/
static void unpackResources() throws FileNotFoundException, IOException {
final int BUFFER = 8192;
android.content.res.Resources t = TestingE3d.mContext.getResources();
InputStream fis = t.openRawResource(R.raw.resources);
if (fis == null)
return;
ZipInputStream zin = new ZipInputStream(new BufferedInputStream(fis,
BUFFER));
ZipEntry entry;
while ((entry = zin.getNextEntry()) != null) {
int count;
FileOutputStream fos = TestingE3d.mContext.openFileOutput(entry
.getName(), 0);
BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER);
byte data[] = new byte[BUFFER];
while ((count = zin.read(data, 0, BUFFER)) != -1) {
dest.write(data, 0, count);
// Log.v("NOTAG", "writing "+count + " to "+entry.getName());
}
dest.flush();
dest.close();
}
zin.close();
}
}
R.raw.resources是一個zip文件 - 該類將解壓縮該zip文件中的所有文件到本地文件夾。 我用這個用於NDK。
你可以從NDK通過訪問您的費爾: /數據/數據//文件/
包=包凡ResLoader所在 名=文件之一是在原始/ resources.zip
你檢查了你的文件大小嗎?由於APK文件是ZIP壓縮文件,如果該資源被壓縮,也許在GZIPping中沒有任何價值。 – CommonsWare 2010-03-02 15:54:43
回聲commonsware,我發現gzipping資產已經完全沒有影響apk的大小,因爲apk的已壓縮。仍然有一個有趣的問題,爲什麼這不起作用(因爲在我的測試過程中,我已經獲得了這樣一個場景以便運行)。 – 2010-03-02 15:56:04
int size = fIn.available(); < - java文檔說:EOF達到後返回0,否則總是返回1. – fazo 2010-03-07 19:24:31