2010-04-19 88 views
0

其實我遇到了一個問題。我在我的應用程序的一個包中有一個「.apk文件」。 apk是一種jar文件(apk = Android Package)。 我現在想將這個jar文件從我的Programm中複製到PC上的任何其他位置。 通常我會用這樣:Java - 複製Jar文件夾

FileInputStream is = new FileInputStream(this.getClass().getResource("/resources/myApp.apk").getFile()); 

然後它用一個FileOutputStream寫在磁盤上。 ...但由於.apk是一種.jar,它不起作用。它只是複製.apk文件。但沒有包含其他文件。

任何幫助,將不勝感激

回答

1

由於.apk.jar文件的另一個名字(換句話說,它是與在配置文件存儲在目錄中的一些具體定義一個zip文件),然後看ZipInputStream到閱讀文件並瀏覽內容並將其作爲文件寫出。

0

非常感謝您伊沙伊......這是我在等待:) 也許提示是某人在那裏,誰需要做同樣的事情,所以...這裏是我的代碼:

public static boolean copyApkFile(File outputFile){ 
     try { 
      FileInputStream fis = new FileInputStream(this.getClass().getResource("/resources/myApkFile.apk").getFile()); 
      ZipInputStream zis = new ZipInputStream(fis); 
      FileOutputStream fos = new FileOutputStream(outputFile)); 
      ZipOutputStream zos = new ZipOutputStream(fos); 
      ZipEntry ze = null; 
      byte[] buf = new byte[1024]; 
      while ((ze = zis.getNextEntry()) != null) { 
       System.out.println("Next entry "+ze.getName()+" "+ze.getSize()); 
       zos.putNextEntry(ze); 
       int len; 
       while ((len = zis.read(buf)) > 0) { 
        zos.write(buf, 0, len); 
       } 
      } 
      zos.close(); 
      fos.close(); 
      zis.close(); 
      fis.close(); 
      return true; 
     } catch (IOException ex) { 
      Logger.getLogger(SetUpNewDevice.class.getName()).log(Level.SEVERE, null, ex); 
      return false; 
     } 
    }