Skip to content

Instantly share code, notes, and snippets.

@JeasonWong
Created January 24, 2017 06:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JeasonWong/70019849c2b39b43922d89ce3cd25412 to your computer and use it in GitHub Desktop.
Save JeasonWong/70019849c2b39b43922d89ce3cd25412 to your computer and use it in GitHub Desktop.
/**
* 解压原始的dex文件
*
* @param context
* @return
* @throws IOException
*/
private String unzipRAWFile(Context context) {
String apkFilePath;
Resources resources = context.getResources();
InputStream inputStream = resources.openRawResource(R.raw.user);
File externalCacheDir = context.getExternalCacheDir();
File file = new File(externalCacheDir, resources.getResourceEntryName(R.raw.user) + ".dex");
apkFilePath = file.getAbsolutePath();
if (!file.exists()) {
BufferedOutputStream bufferedOutputStream = null;
FileOutputStream fileOutputStream = null;
try {
fileOutputStream = new FileOutputStream(file);
bufferedOutputStream = new BufferedOutputStream(fileOutputStream);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
byte[] buffer = new byte[4 * 1024];
int size;
try {
while ((size = inputStream.read(buffer)) != -1) {
bufferedOutputStream.write(buffer, 0, size);
bufferedOutputStream.flush();
}
} catch (IOException e) {
e.printStackTrace();
}
try {
if (inputStream != null)
inputStream.close();
if (bufferedOutputStream != null)
bufferedOutputStream.close();
if (fileOutputStream != null)
fileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
Log.i("@@@", "文件解压完毕,路径地址为:" + apkFilePath);
} else {
Log.i("@@@", "文件已存在,无需解压");
}
return apkFilePath;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment