zoukankan      html  css  js  c++  java
  • gzip

    public class Gzip {
    
        /**
         * gzip file
        */
        public void gzip(String fis, String fos) {
            try {
                FileInputStream fin = new FileInputStream(fis);
                FileOutputStream fout = new FileOutputStream(fos);
                GZIPOutputStream gzout = new GZIPOutputStream(fout);
                byte[] buf = new byte[1024];// 
                int num;
    
                while ((num = fin.read(buf)) != -1) {
                    gzout.write(buf, 0, num);
                }
                gzout.close();// !!!Don't forget to release the source
                fout.close();
                fin.close();
            } catch (IOException e) {
                System.out.println(e);
            }
        }
        
        /**
         * extract file from gzip
        */
        public void unzip(String fis, String fos) {
            try {
                FileInputStream fin = new FileInputStream(fis);
                GZIPInputStream gzin = new GZIPInputStream(fin);
                FileOutputStream fout = new FileOutputStream(fos);
                byte[] buf = new byte[1024];
                int num;
                while ((num = gzin.read(buf, 0, buf.length)) != -1) {
                    fout.write(buf, 0, num);
                }
                gzin.close();
                fout.close();
                fin.close();
            } catch (IOException e) {
                System.out.println(e);
            }
        }
        
        public static void main(String[] args) throws FileNotFoundException {
            String path="/home/siya/local/test";
            String file="localfile";
            String gzfile="localfile.gz";
            String fis=path+File.separator+file;
            String fos=path+File.separator+gzfile;
    //        new Gzip().unzip(fis, fos);
            new Gzip().gzip(fis, fos);
        }
        
    }
  • 相关阅读:
    [转]MYSQL5.7版本sql_mode=only_full_group_by问题
    [坑]Linux MySQL环境表名默认区分大小写
    [转]CentOS 7.3 安装MySQL
    [转]Oracle截取字符串相关函数
    服务相关
    CSRF攻击
    sqlalchemy——多表操作
    sqlalchemy——基本操作
    高可用——网站运行监控
    高可用——软件质量保证
  • 原文地址:https://www.cnblogs.com/lansor/p/2537942.html
Copyright © 2011-2022 走看看