JAVA ZIP 處理檔案

weixin_34126215發表於2014-09-18

壓縮檔案

    public static void main(String[] args) throws IOException {
        String filePath = "E:\\技術部員工工作";
        ZipOutputStream outputStream = new ZipOutputStream(new FileOutputStream("E:\\技術部員工工作\\aaa.zip"));
        
        ZipEntry entry = new ZipEntry("dadsa.txt");
        byte[] d = FileUtils.readFileToByteArray(new File(filePath + "\\20140417.txt"));
        outputStream.putNextEntry(entry);
        outputStream.write(d);
        outputStream.closeEntry();
        //outputStream.closeEntry();
        ZipEntry entry1 = new ZipEntry("da1dsa.txt");
        byte[] d1 = FileUtils.readFileToByteArray(new File(filePath + "\\20140916.txt"));
        outputStream.putNextEntry(entry1);
        outputStream.write(d1);
        outputStream.closeEntry();
        
        outputStream.finish();
        outputStream.close();
    }

 

相關文章