小编Ale*_*eev的帖子

GZIP解压缩字符串和字节转换

我的代码有问题:

private static String compress(String str)
{
    String str1 = null;
    ByteArrayOutputStream bos = null;
    try
    {
        bos = new ByteArrayOutputStream();
        BufferedOutputStream dest = null;

        byte b[] = str.getBytes();
        GZIPOutputStream gz = new GZIPOutputStream(bos,b.length);
        gz.write(b,0,b.length);
        bos.close();
        gz.close();

    }
    catch(Exception e) {
        System.out.println(e);
        e.printStackTrace();
    }
    byte b1[] = bos.toByteArray();
    return new String(b1);
}

private static String deCompress(String str)
{
    String s1 = null;

    try
    {
        byte b[] = str.getBytes();
        InputStream bais = new ByteArrayInputStream(b);
        GZIPInputStream gs = new GZIPInputStream(bais);
        ByteArrayOutputStream baos …
Run Code Online (Sandbox Code Playgroud)

java gzip gzipoutputstream

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

gzip ×1

gzipoutputstream ×1

java ×1