zoukankan      html  css  js  c++  java
  • 公用方法

    //文件转换为字节  
    public static byte[] File2Bytes(string path) { if (!System.IO.File.Exists(path)) { return new byte[0]; } FileInfo fi = new FileInfo(path); byte[] buff = new byte[fi.Length]; FileStream fs = fi.OpenRead(); fs.Read(buff, 0, Convert.ToInt32(fs.Length)); fs.Close(); return buff; }

      

    //生成压缩文件
    public static void CompressedFiles(string topDirectoryName, string zipedFileName, int compresssionLevel, string password, string comment) { using (ZipOutputStream zos = new ZipOutputStream(System.IO.File.Open(zipedFileName, FileMode.OpenOrCreate))) { if (compresssionLevel != 0) { zos.SetLevel(compresssionLevel);//设置压缩级别 } if (!string.IsNullOrEmpty(password)) { zos.Password = password;//设置zip包加密密码 } if (!string.IsNullOrEmpty(comment)) { zos.SetComment(comment);//设置zip包的注释 } //循环设置目录下所有的*.png文件(支持子目录搜索) foreach (string file in Directory.GetFiles(topDirectoryName, "*.txt", SearchOption.AllDirectories)) { if (System.IO.File.Exists(file)) { FileInfo item = new FileInfo(file); FileStream fs = System.IO.File.OpenRead(item.FullName); byte[] buffer = new byte[fs.Length]; fs.Read(buffer, 0, buffer.Length); ZipEntry entry = new ZipEntry(item.Name); zos.PutNextEntry(entry); zos.Write(buffer, 0, buffer.Length); } } } }

      

  • 相关阅读:
    django
    水仙花数 Python
    Python 实现两个矩形重合面积
    Linux文件目录
    grep 命令
    软件测试的一些心得(转)
    压力测试和负载测试
    如何在mysql数据库生成百万条数据来测试页面加载速度
    CentOS7下部署java+tomcat+mysql项目及遇到的坑
    MongoDB的安装
  • 原文地址:https://www.cnblogs.com/opts/p/13231325.html
Copyright © 2011-2022 走看看