zip文件的解壓,獲取字節流


/**
     * 
     * @param inputStream 輸入流
     * @return 返回數據
     */
    private static String decompress(InputStream inputStream) {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ZipInputStream zipInputStream = new ZipInputStream(inputStream);
        String rtn = null;
        try {
            while (zipInputStream.getNextEntry() != null) {
                int size = 0;
                byte[] buffer = new byte[1024];
                while (true) {
                    size = zipInputStream.read(buffer, 0, buffer.length);
                    if (size <= 0) {
                        break;
                    }
                    bos.write(buffer, 0, size);
                }
                bos.flush();
                bos.close();
            }
            zipInputStream.close();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                byte[] be = bos.toByteArray();
                rtn = new String(be, "utf-8");
                bos.flush();
                bos.close();
                zipInputStream.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return rtn;
    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM