集册 Java实例教程 提取Apk文件

提取Apk文件

欢马劈雪     最近更新时间:2020-01-02 10:19:05

631
提取Apk文件


import java.io.BufferedInputStream;
/*
时 代 J     a    v  a - nowjava.com
*/

import java.io.FileOutputStream;

import java.io.IOException;

import java.util.ArrayList;

import java.util.Enumeration;

import java.util.List;

import java.util.jar.JarFile;

import java.util.logging.Level;

import java.util.logging.Logger;

import java.util.zip.ZipEntry;

import java.util.zip.ZipFile;
/**
 * 时 代 J a v a 提 供 
**/


public class Main{

    public static void main(String[] argv) throws Exception{

        String apkPath = "nowjava.com";

        System.out.println(extractApks(apkPath));

    }

    public static int BUFFER = 2048;

    public synchronized static List<String> extractApks(String apkPath) {

        List<String> ret = new ArrayList<String>();

        try {

            ZipFile zip = new ZipFile(apkPath);

            Enumeration<? extends ZipEntry> entries = zip.entries();

            while (entries.hasMoreElements()) {

                ZipEntry entry = entries.nextElement();

                if (entry.getName().endsWith(".apk")) {

                    // Get a new tmp file

                    String tmpFilePath = FileUtil.getTempFile("apktmp_",

                            ".apk");

                    FileOutputStream fos = new FileOutputStream(tmpFilePath);

                    BufferedInputStream is = new BufferedInputStream(

                            zip.getInputStream(entry));

                    // Get it out of the box

                    int count = 0;

                    byte[] buf = new byte[BUFFER];

                    count = is.read(buf, 0, BUFFER);

                    while ((count = is.read(buf, 0, BUFFER)) != -1) {

                        fos.write(buf, 0, count);

                    }

                    fos.flush();

                    fos.close();


                    
展开阅读全文