zoukankan      html  css  js  c++  java
  • 解压Zip包

    解压Zip包:

    def unZipFile(zipFile:String , descDir:String ):Boolean ={
        var flag = true
        try {
            val pathFile:File = new File(descDir)
            if (!pathFile.exists) {
                pathFile.mkdirs
            }
            val zip = new ZipFile(new File(zipFile), Charset.forName("UTF-8"))
    //        val entries = zip.entries.asInstanceOf[Enumeration[ZipEntry]]
            val entries = zip.entries.asInstanceOf[util.Enumeration[ZipEntry]]
            while (entries.hasMoreElements){
                // val entry = entries.nextElement.asInstanceOf[ZipFile]
                val entry = entries.nextElement
                val zipEntryName = entry.getName
                val in = zip.getInputStream(entry)
                val outPath = (descDir + zipEntryName).replaceAll("\*", "/")
                //判断路径是否存在,不存在则创建文件路径
                val file = new File(outPath.substring(0, outPath.lastIndexOf('/')))
                if (!file.exists) {
                    file.mkdirs
                }
                //判断文件全路径是否为文件夹,如果是上面已经上传,不需要解压
                if (!new File(outPath).isDirectory()) {
                    //输出文件路径信息
                    println(outPath)
                    val out = new FileOutputStream(outPath)
                    //val writer = new PrintWriter(new File(outPath))
                    val buf1 = Array[Byte]()
                    while((in.read(buf1))>0){
                        in.read
                        out.write(buf1)
                    }
                    // out.close
                }
                in.close
            }
        }catch{
            case e: ZipException =>
                flag = false
            case e: FileNotFoundException =>
                flag = false
            case e: IOException =>
                flag = false
        }
        println("******************解压完毕********************")
        flag
    }
    
    
        def main(args: Array[String]): Unit = {
            unZipFile("E:/test/zhangsan.zip", "E:/zip")
        }
    

      

  • 相关阅读:
    【刷题】洛谷 P4319 变化的道路
    【刷题】BZOJ 4573 [Zjoi2016]大森林
    CSS3_天猫商品墙
    CSS3_3D 变换
    CSS3_扇形导航_transitionend 事件
    CSS3_过渡_2D 变换_瓶体旋转_动态时钟
    CSS3_多列布局
    CSS3_线性渐变_径向渐变----背景
    CSS3_盒子背景
    CSS3_盒阴影_倒影_盒子大小可调
  • 原文地址:https://www.cnblogs.com/wangxiaowang/p/7818915.html
Copyright © 2011-2022 走看看