「Java入門」java.util.zip.GZIPOutputStream()でファイルを圧縮する方法

Javaコード
public static byte[] compress(String targetStr, String encodStr) {
if (targetStr == null || targetStr.length() == 0) {
return null;
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
GZIPOutputStream gzip;
try {
gzip = new GZIPOutputStream(out);
gzip.write(str.getBytes(encodStr));
gzip.close();
} catch (IOException e) {
log.error(e);
}
return out.toByteArray();
}

Comments are closed.