<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    壓縮文件以及文件夾

    @import url(http://www.tkk7.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
    //使用Groovy 稍微改了下
    import
     java.io.File;
    import java.io.FileInputStream;
    import java.util.zip.GZIPOutputStream 
    import java.util.zip.ZipEntry 
    import java.util.zip.ZipOutputStream 


    class Compress {
        
        
    public static gzipFile(from,to) throws IOException{
            def inFile 
    = new FileInputStream(from);
            def out 
    = new GZIPOutputStream(new FileOutputStream(to));
            
    byte[] buffer = new byte[4096];
            def buffer_read 
    = 0;
            
    while((buffer_read = inFile.read(buffer)) != -1){
    //            out.write(buffer,0,buffer_read);//use '<<' replace
                out << buffer;//use '<<' replace
            }
            inFile.close();
            out.close();
        }
        
        
    public static zipDirectory(dir,zipFile){
            File dire 
    = new File(dir);
            
    if(!dire.isDirectory()){
                
    throw new IllegalArgumentException('Compress: not a directory:' + dir);
            }
            String[] entries 
    = dire.list();
            
    byte[] buffer = new byte[4096];
            
    int bytes_read;
            
            ZipOutputStream out 
    = new ZipOutputStream(new FileOutputStream(zipFile));
            
            entries.each{item 
    ->
                File f 
    = new File(dire,item);
                
    if(f.isDirectory()){
                    
    return ;
                }
                FileInputStream in_file 
    = new FileInputStream(f);
                ZipEntry entry 
    = new ZipEntry(f.getPath());
                out.putNextEntry (entry);
                
    while((bytes_read = in_file.read(buffer)) != -1){
                    out 
    << buffer;
                }
                in_file.close();
            }
            out.close();
        }
        
        
    static main(args) {
            def from 
    = args[0];
            File from_file 
    = new File(from);
            def directory 
    = from_file.isDirectory();
            def to 
    = '';
            
    if(directory){
                to 
    = from + '.zip';
            }
    else{
                to 
    = from + '.gz';
            }
            
            
    if((new File(to)).exists()){
                println(
    'Compress: won\'t overwrite existing file:' + to);
                System.exit(0);
            }
            
    if(directory)
                Compress.zipDirectory (from, to);
            
    else
                Compress.gzipFile from, to;
        }
    }


    Kyle Wang

    posted on 2011-07-22 12:55 王樹東 閱讀(292) 評論(0)  編輯  收藏 所屬分類: Code Templates

    <2011年7月>
    262728293012
    3456789
    10111213141516
    17181920212223
    24252627282930
    31123456

    導航

    統計

    公告

    常用鏈接

    留言簿

    隨筆分類(17)

    隨筆檔案(15)

    文章分類(4)

    文章檔案(5)

    收藏夾(4)

    Algorithm

    Design

    Environment Setup

    Installer

    Maven

    MINA

    OS

    Skills for Java

    VIM

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲精品无码久久久| 日本成年免费网站| 在线精品亚洲一区二区三区| www亚洲精品久久久乳| 国产精品99久久免费| 精品在线观看免费| 亚洲成a人片在线播放| 亚洲一级片免费看| 国产亚洲精品福利在线无卡一| 国内精品99亚洲免费高清| 456亚洲人成影院在线观| 永久免费在线观看视频| 亚洲专区一路线二| 狼友av永久网站免费观看| 最新亚洲人成网站在线观看 | 亚洲精品视频在线免费| 四虎在线成人免费网站| 亚洲中文字幕无码中文| 免费国产怡红院在线观看| 中文字幕不卡免费视频| 免费高清在线爱做视频| 一级做a爰片性色毛片免费网站| 国内精品免费麻豆网站91麻豆| 亚洲精品人成网在线播放影院| 日韩一级在线播放免费观看| 羞羞网站免费观看| 亚洲日韩精品一区二区三区| 亚洲成人在线免费观看| 无遮挡国产高潮视频免费观看| 亚洲av无码不卡| 午夜宅男在线永久免费观看网| 曰批免费视频播放免费| 亚洲成人在线网站| 国产男女猛烈无遮挡免费网站 | 国产亚洲一区二区在线观看| 高潮毛片无遮挡高清免费| 亚洲精品午夜国产VA久久成人| 免费A级毛片无码无遮挡内射| 特级av毛片免费观看| 亚洲国产精品成人久久久| 亚洲AV成人精品日韩一区18p|