zoukankan      html  css  js  c++  java
  • java无需解压zip压缩包直接读取包内的文件名(含中文)

    java自带了java.util.zip工具可以实现在不解压zip压缩包的情况下读取包内文件的文件名:(注:只能是ZIP格式的,rar我试了不行)代码如下:

    public static String readZipFile(String path, String str) throws IOException {
            ZipEntry zipEntry = null;
            File file = new File(path); 
            if(file.exists()){ //判断文件是否存在
                ZipInputStream zipInputStream = new ZipInputStream( new FileInputStream(path), Charset.forName("GBK")); //解决包内文件存在中文时的中文乱码问题
                while ((zipEntry = zipInputStream.getNextEntry()) != null) {
                    if(zipEntry.isDirectory()){ //遇到文件夹就跳过
                        continue;
                    }else{
                      
                            str+=";"+zipEntry.getName().substring(zipEntry.getName().lastIndexOf("/")+1);
    // System.out.println(zipEntry.getName().substring(zipEntry.getName().lastIndexOf("/")+1));//通过getName()可以得到文件名称 } } } return str; }
  • 相关阅读:
    HDU 5937 Equation
    HDU 5936 Difference
    hdu 4348 To the moon
    SPOJ QTREE Query on a tree
    HDU 3966 Aragorn's Story
    Codeforces 733F Drivers Dissatisfaction
    道良心题
    dp小总结
    数据结构
    数学相关(偏数学向题目的集中地)
  • 原文地址:https://www.cnblogs.com/mlorct/p/10696789.html
Copyright © 2011-2022 走看看