Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
* 解压原始的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