Created
January 24, 2017 06:18
-
-
Save JeasonWong/70019849c2b39b43922d89ce3cd25412 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 解压原始的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