Android 解压中文乱码(压缩包内中文乱码)
生活随笔
收集整理的這篇文章主要介紹了
Android 解压中文乱码(压缩包内中文乱码)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
?
首先下載apache-ant-zip.jar,導(dǎo)入到自己的項目中
apache-ant-zip.jar的地址:https://download.csdn.net/download/wshiyf/8993883?locationNum=13&fps=1
之后就是代碼:
?
/*** 解壓縮* 將zipFile文件解壓到folderPath目錄下.** @param zipFile zip文件所在的地址,new成file* @param folderPath 解壓到的地址* @throws IOException*/ public static void upZipFile(File zipFile, String folderPath) throws IOException {ZipFile zf = null;BufferedOutputStream bos=null;BufferedInputStream bi = null;try {List<String> mList = new ArrayList<>();zf = new ZipFile(zipFile, "GBK");Enumeration e = zf.getEntries();while (e.hasMoreElements()){ZipEntry ze2 = (ZipEntry) e.nextElement();String entryName = ze2.getName();String path = folderPath + "/" + entryName;if (ze2.isDirectory()){System.out.println("正在創(chuàng)建解壓目錄 - " + entryName);Log.d("zipFileUtil","正在創(chuàng)建解壓目錄 - " + entryName);File decompressDirFile = new File(path);if (!decompressDirFile.exists()){decompressDirFile.mkdirs();}} else{System.out.println("正在創(chuàng)建解壓文件 - " + entryName);Log.d("zipFileUtil","正在創(chuàng)建解壓文件 - " + entryName);mList.add(folderPath + "/" + entryName);String fileDir = path.substring(0, path.lastIndexOf("/"));File fileDirFile = new File(fileDir);if (!fileDirFile.exists()){fileDirFile.mkdirs();}bos = new BufferedOutputStream(new FileOutputStream(folderPath + "/" + entryName));bi = new BufferedInputStream(zf.getInputStream(ze2));byte[] readContent = new byte[1024];int readCount = bi.read(readContent);while (readCount != -1){bos.write(readContent, 0, readCount);readCount = bi.read(readContent);}bos.close();}}zf.close();for (int i = 0; i < mList.size(); i++) {Log.d("zipFileUtil====",mList.get(i));}} catch (IOException ex) {throw ex;} finally {if (null != zf) {zf.close();}if (null != bi) {bi.close();}if (null != bos) {bos.close();}}}?
總結(jié)
以上是生活随笔為你收集整理的Android 解压中文乱码(压缩包内中文乱码)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: PHP 开发基础知识笔记
- 下一篇: Android解压ZIP