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

        public static void parseZIP(String path,String filename,String resourcePath){
            System.out.println("filename:"+filename);
            String filename0 = filename.substring(0, filename.lastIndexOf("."));
            createFile(filename0);
            String pathDir = createDirs(filename0,resourcePath);
            
            try {
                // destination folder to extract the contents
                byte[] buf = new byte[1024];
                ZipInputStream zipinputstream = null;
                ZipEntry zipentry;
                zipinputstream = new ZipInputStream(new FileInputStream(path));
                zipentry = zipinputstream.getNextEntry();
                while (zipentry != null) {
     
                    // for each entry to be extracted
                    String entryName = zipentry.getName();
    
    //                System.out.println(entryName);
     
                    int n;
                    FileOutputStream fileoutputstream;
    //                File newFile = new File(entryName);
     
                    if (!zipentry.isDirectory()) {
    //                    System.out.println("File to be extracted....." + entryName);
                        fileoutputstream = new FileOutputStream(pathDir+File.separator+entryName);
                        while ((n = zipinputstream.read(buf, 0, 1024)) > -1) {
                            fileoutputstream.write(buf, 0, n);
                        }
                        fileoutputstream.close();
                    }
     
                    zipinputstream.closeEntry();
                    zipentry = zipinputstream.getNextEntry();
                }
                zipinputstream.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
            
        }
        //解析 Rar文件  放到指定的目录 环境
        public static void parseRAR(String path,String filename,String resourcePath) {
            
            if(!path.toLowerCase().endsWith(".rar")){
                
            }
            
            String filename0 = filename.substring(0, filename.indexOf(".rar"));
            createFile(filename0);
            String pathDir = createDirs(filename0,resourcePath);
            FileOutputStream  out = null; 
            Archive a = null;
    
            try {
                a = new Archive(new File(path));
                
                FileHeader fh = a.nextFileHeader();
                
                while(fh != null){
    
                    String name = fh.getFileNameString();
                    out = new FileOutputStream(new File(pathDir+File.separator+name));
                    a.extractFile(fh, out);
                    fh = a.nextFileHeader();
                    out.close();
                }
    
                a.close();
            } catch (RarException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }catch(Exception e){
                e.printStackTrace();
            }
            
            //System.out.println("--------------end--------------");
        }
        
        //解析Rar文件 得到里面配置文件 并得到配置文件名称 :包名
        private static  String  getPackageName(String path){
        
            if(!path.toLowerCase().endsWith(".rar")){
                
            }
            BufferedOutputStream  out = null; 
            String retValue = "";
            Archive a = null;
            try {
                a = new Archive(new File(path));
                FileHeader fh = a.nextFileHeader();
                while(fh != null){
                    if(!fh.isDirectory()&&fh.getFileNameString().endsWith(".txt")){
                        
                        retValue = fh.getFileNameString();
                        retValue = retValue.substring(retValue.indexOf(File.separator)+1,retValue.lastIndexOf(".txt"));
                        out = new BufferedOutputStream(new FileOutputStream(new File(ParseConfig.getValue("configFiles")+File.separator+retValue+".txt")));
                        a.extractFile(fh, out);
                        out.flush();
                        out.close();
                        break;
                    }
                    fh = a.nextFileHeader();
                }
    
                a.close();
            } catch (RarException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        
            return retValue;
        }
        
  • 相关阅读:
    Introduction to debugging neural networks
    Faster R-CNN教程
    最长递增子序列
    321. Create Maximum Number 解题方法详解
    Ubuntu安装opencv with cuda
    转载:LeetCode:5Longest Palindromic Substring 最长回文子串
    64. Minimum Path Sum
    322. Coin Change
    148. Sort List
    微信浏览器禁止页面下拉查看网址(不影响页面内部scroll)
  • 原文地址:https://www.cnblogs.com/phyxis/p/5256838.html
Copyright © 2011-2022 走看看