压缩Android中的字符串文件

时间:2014-02-25 09:46:53

标签: android compression gzip

我将一些字符串值存储在一个文件中。此文件始终已更新。我必须减小文件的大小。

所以我尝试的选项是使用 gzip 并压缩字符串值,然后将其存储为字节。但规模并没有大幅减少。有没有其他方法可以减小文件的大小。

我目前用于压缩字符串值的代码如下所示。

public static byte[] compress(String string) throws IOException {
    ByteArrayOutputStream os = new ByteArrayOutputStream(string.length());
    GZIPOutputStream gos = new GZIPOutputStream(os);
    gos.write(string.getBytes());
    gos.close();
    byte[] compressed = os.toByteArray();
    os.close();
    return compressed;
}   

0 个答案:

没有答案
相关问题