3
A
回答
6
您可以使用java.util.jar.JarFile
遍歷文件中的條目,通過其InputStream
提取每個條目並將數據寫入外部文件。 Apache Commons IO提供了實用程序,使其不那麼笨拙。
2
Jar基本上是使用ZIP算法壓縮的,所以你可以使用winzip或winrar來提取。
如果您正在尋找編程方式,那麼第一個答案是更正確的。
1
從命令行類型jar xf foo.jar
或unzip foo.jar
4
ZipInputStream in = null;
OutputStream out = null;
try {
// Open the jar file
String inFilename = "infile.jar";
in = new ZipInputStream(new FileInputStream(inFilename));
// Get the first entry
ZipEntry entry = in.getNextEntry();
// Open the output file
String outFilename = "o";
out = new FileOutputStream(outFilename);
// Transfer bytes from the ZIP file to the output file
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
} catch (IOException e) {
// Manage exception
} finally {
// Close the streams
if (out != null) {
out.close();
}
if (in != null) {
in.close();
}
}
1
使用Ant unzip task。
相關問題
- 1. 最簡單的方法來創建JAR?
- 2. 最簡單的方法來壓縮Python和解壓縮C#(反之亦然)
- 3. 在Java中壓縮現有文件的簡單方法?
- 4. 瞭解MongoDB的最簡單方法iphone
- 5. Java簡單的解析XML的方法
- 6. 在c中解析的簡單方法#
- 7. 簡單的方法在Java中使用
- 8. 在java中調用簡單的方法
- 9. iPhone上最簡單的方法來解壓縮下載的文件?
- 10. 在Java中解析INI文件的最簡單方法是什麼?
- 11. 在Java中解析這個XML的最簡單方法是什麼?
- 12. Java中Jar方法的單元測試
- 13. 在C#中解析Javascript日期的最簡單方法?
- 14. 在Qt 4.7中解析JSON的最簡單方法
- 15. 最簡單的方法在Java中旋轉圖像
- 16. 在Java中實現定時器事件的最簡單方法
- 17. 在java中構建IDE最簡單的方法是什麼?
- 18. 在Java中拉取JSON URL最簡單的方法是什麼?
- 19. 在Java中使用LDAP的最簡單方法(Eclipse)
- 20. 在java中訪問json值的最簡單方法
- 21. 在Java中實現Scala PartialFunction的最簡單方法是什麼?
- 22. 在Java中切換布爾變量的最簡單方法?
- 23. 在Java中繪製圖元的最簡單方法(不是OpenGL)
- 24. 在Java中創建GUI的最簡單方法是什麼?
- 25. Clojure - 將PDF/Doc文件解壓縮爲簡單文本的最佳方法
- 26. 最簡單的方法
- 27. 最簡單的方法
- 28. 最簡單的方法
- 29. 最簡單的方法
- 30. 最簡單的方法
在OP從junit測試執行的情況下不起作用。 – Chadwick 2009-08-19 18:10:15