我必須使用哪個庫來處理android上的檔案(如rar,zip)。一些示例代碼。我找不到任何存檔文件的例子。Android RAR,zip庫
回答
您是壓縮還是解壓縮? (或兩者?) 以前我用過ZipInputStream。 您使用的策略可能取決於Zip存儲位置(在SD卡上/在APK資源中/在APK擴展中)。 例如,如果它是一項資產,您可以使用AssetManager將文件作爲InputSteam打開。 如果它在SD卡上,則可能需要使用ZipFile。
這裏有一個Java教程,可以幫助: http://java.sun.com/developer/technicalArticles/Programming/compression/
我想使用存檔文件而不解壓縮到SDcard。我有文件存檔,我想與這些文件工作。 – Lang 2012-03-20 09:54:16
那麼你是否正在調查內容而沒有提取任何東西? – HaemEternal 2012-03-20 09:57:55
是的。並使用這個文件 – Lang 2012-03-20 10:04:21
的拉鍊可以使用java.util.Zip,對RAR壓縮包,我認爲你必須要經過第三方庫
看到這個例子
public void unzip() {
try {
FileInputStream fin = new FileInputStream(_zipFile);
ZipInputStream zin = new ZipInputStream(fin);
ZipEntry ze = null;
while ((ze = zin.getNextEntry()) != null) {
Log.v("Decompress", "Unzipping " + ze.getName());
System.out.println("^^^^^^UnzippingFile^"+ze.getName());
///code to search is given string exists or not in a Sentence
String haystack = ze.getName();
String needle1 = ".DS_Store";
int index1 = haystack.indexOf(needle1);
if (index1 != -1)
{
System.out.println("The string contains the substring "
+ needle1);
continue;
}
/*else
System.out.println("The string does not contain the
substring " + needle1);*/
if(ze.isDirectory()) {
_dirChecker(ze.getName());
} else {
FileOutputStream fout = new FileOutputStream(_location +
ze.getName());
// replace for loop with:
byte[] buffer = new byte[1024];
int length;
while ((length = zin.read(buffer))>0) {
fout.write(buffer, 0, length);
}
zin.closeEntry();
fout.close();
}
}////Outer While
zin.close();
} catch(Exception e) {
Log.e("Decompress", "unzip", e);
}
}
private void _dirChecker(String dir) {
File f = new File(_location + dir);
if(!f.isDirectory()) {
f.mkdirs();
}
}
右鍵點擊你的項目--->屬性 - - > Java Build path ----> Libraries ---> Add External Jar 然後以任何格式在您的項目中添加庫.zip或.rar
- 1. 帶SWIFT的Zip/Rar文件
- 2. 自動打開ZIP/RAR
- 3. 將.rar文件從.rar傳輸到.zip而不提取
- 4. Android庫zip
- 5. PHP庫,可以列出zip/rar文件的內容
- 6. 上傳docx,zip,rar,pdf,ppt,在php中
- 7. Python:How to convert .7z to .rar or .zip?
- 8. 在Joomla創建zip/rar/tar文件夾
- 9. Ruby/rubyzip替代能夠處理rar/tar/zip/7z嗎?
- 10. 如何在下載之前查看rar或zip文件內容?
- 11. cURL Mail Attachment(Imagines,.exe文件,.rar/.zip文件)
- 12. 使用Python將.rar格式轉換爲.zip
- 13. 如何創建rar/zip文件和下載
- 14. 如何下載用的file_get_contents PHP生成的ZIP/RAR文件
- 15. 檢查文件是否存檔(zip或rar)使用php
- 16. 如何查看和下載DOC,PDF,PPT,ZIP,RAR,在laravel
- 17. Android中的解壓縮Rar文件
- 18. RAR文件的InputStream
- 19. Android SDK Zip存檔
- 20. 如何提取目錄中的所有多部分ZIP/RAR存檔?
- 21. 自動上傳和解壓檔案(zip,rar,targz,tarbz) - 安全問題?
- 22. 是否有可能讀取Windows Phone 7內的.rar或.zip文件?怎麼樣?
- 23. 將文件上傳到虛擬主機以進行即時下載(.zip,.rar)
- 24. Python內存中的zip庫
- 25. java庫使用Zip文件
- 26. 下載android SDK,.exe或.zip?
- 27. Android zip文件認證
- 28. Android Zip文件訪問
- 29. Android下載Zip到SD卡?
- 30. 從zip創建文件 - android
這已被問過[這裏RAR(http://stackoverflow.com/questions/561107/rar-archives-with-java)和[這裏是zip](http://stackoverflow.com/questions/9558595/android-library-zip)。請嘗試先搜索。 – RivieraKid 2012-03-20 09:41:11
可能使用[RAR archives with java]重複(https://stackoverflow.com/questions/561107/rar-archives-with-java) – 2017-08-30 00:03:35