开发学院手机开发Android 开发 Android Java压缩Zlib,Gzip,Zip支持J2ME 阅读

Android Java压缩Zlib,Gzip,Zip支持J2ME

 2010-11-05 00:54:54 来源:WEB开发网   
核心提示:** @param data* @return* @throws IOException*/public static byte[] zip(byte[] bContent) throws IOException{byte[] b = null;try{ByteArrayOutputStream bos = new B

*

* @param data

* @return

* @throws IOException

*/

public static byte[] zip(byte[] bContent) throws IOException

{

byte[] b = null;

try

{

ByteArrayOutputStream bos = new ByteArrayOutputStream();

ZipOutputStream zip = new ZipOutputStream(bos);

ZipEntry entry = new ZipEntry("zip");

entry.setSize(bContent.length);

zip.putNextEntry(entry);

zip.write(bContent);

zip.closeEntry();

zip.close();

b = bos.toByteArray();

bos.close();

}

catch (Exception ex)

{

ex.printStackTrace();

}

return b;

}

/***

* 解压Zip

*

* @param data

* @return

* @throws IOException

*/

public static byte[] unZip(byte[] bContent) throws IOException

{

byte[] b = null;

try

{

ByteArrayInputStream bis = new ByteArrayInputStream(bContent);

ZipInputStream zip = new ZipInputStream(bis);

while (zip.getNextEntry() != null)

{

byte[] buf = new byte[1024];

int num = -1;

ByteArrayOutputStream baos = new ByteArrayOutputStream();

while ((num = zip.read(buf, 0, buf.length)) != -1)

{

baos.write(buf, 0, num);

}

b = baos.toByteArray();

baos.flush();

baos.close();

}

zip.close();

bis.close();

}

catch (Exception ex)

{

ex.printStackTrace();

}

return b;

}

public static void main(String[] args)

{

String newContent = "";

try

{

String content =

上一页  1 2 3 4 5 6  下一页

Tags:Android Java 压缩

编辑录入:coldstar [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接