{"id":2221,"date":"2015-06-12T10:13:00","date_gmt":"2015-06-12T10:13:00","guid":{"rendered":"http:\/\/www.gisdeveloper.co.kr\/?p=2221"},"modified":"2020-08-22T11:45:43","modified_gmt":"2020-08-22T02:45:43","slug":"java-file%ec%97%90-%eb%8c%80%ed%95%9c-zip-%ec%95%95%ec%b6%95","status":"publish","type":"post","link":"http:\/\/www.gisdeveloper.co.kr\/?p=2221","title":{"rendered":"[Java] File\uc5d0 \ub300\ud55c Zip \uc555\ucd95"},"content":{"rendered":"<p><P>\uc5ec\ub7ec\uac1c\uc758 \ud30c\uc77c\ub4e4\uc744 \ud558\ub098\uc758 Zip \ud30c\uc77c\ub85c \uc555\ucd95\ud558\ub294 \uc790\ubc14 \ucf54\ub4dc\uc785\ub2c8\ub2e4. <\/P><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\">\r\nString zipFileName = \"c:\/file.zip\";\r\n\r\nString[] files = new String[3];\r\n\r\nfiles[0] = \"c:\/a.so\";\r\nfiles[1] = \"c:\/b.dat\";\r\nfiles[2] = \"c:\/c.cfg\";\r\n\t\t\r\nbyte[] buf = new byte[4096];\r\n\r\ntry {\r\n    ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipFileName));\r\n\r\n    for (int i=0; i&lt;files.length; i++) {\r\n        FileInputStream in = new FileInputStream(files[i]);\r\n        Path p = Paths.get(files[i]);\r\n        String fileName = p.getFileName().toString();\r\n\t        \t\r\n        ZipEntry ze = new ZipEntry(fileName);\r\n        out.putNextEntry(ze);\r\n\t      \r\n        int len;\r\n        while ((len = in.read(buf)) > 0) {\r\n            out.write(buf, 0, len);\r\n        }\r\n\t      \r\n        out.closeEntry();\r\n        in.close();\r\n\r\n    }\r\n\t      \r\n    out.close();\r\n} catch (IOException e) {\r\n    e.printStackTrace();\r\n}\r\n<\/pre>\n<p><P>a.so, a.dat, c.cfg \ud30c\uc77c \uc138\uac1c\ub97c file.zip\uc73c\ub85c \uc555\ucd95\ud569\ub2c8\ub2e4. \ud2b9\ud788, 19\ubc88 \ucf54\ub4dc\uc758 ZipEntry\uc758 \uc0dd\uc131\uc790\uc758 \uc778\uc790\uc5d0 \uacbd\ub85c\uac00 \ub4e4\uc5b4\uac08 \uacbd\uc6b0 \uc555\ucd95 \ud30c\uc77c \ub0b4\ubd80\uc5d0\ub3c4 \ub3d9\uc77c\ud55c \uacbd\ub85c\uac00 \ud615\uc131\ub429\ub2c8\ub2e4. \ucf54\ub4dc \ucd5c\uc800\ud654\ub294 \uac01\uc790\uc758 \ubaab\uc73c\ub85c \ub0a8\uaca8 \ub461\ub2c8\ub2e4.<\/P><\/p>\n<p><P>\ucc38\uace0\ub85c \uc704\uc758 \ud074\ub798\uc2a4\ub4e4\uc744 \uc704\ud574 \ud544\uc694\ud55c import \ubb38\uc758 \uc0bd\uc785\uc744 \uc704\ud574 \uc774\ud074\ub9bd\uc2a4\uc5d0\uc11c\ub294 ^~O (Ctrl+Shift+O)\ub97c \uc785\ub825\ud558\uc2dc\uba74 \ub429\ub2c8\ub2e4.<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\uc5ec\ub7ec\uac1c\uc758 \ud30c\uc77c\ub4e4\uc744 \ud558\ub098\uc758 Zip \ud30c\uc77c\ub85c \uc555\ucd95\ud558\ub294 \uc790\ubc14 \ucf54\ub4dc\uc785\ub2c8\ub2e4. String zipFileName = &#8220;c:\/file.zip&#8221;; String[] files = new String[3]; files[0] = &#8220;c:\/a.so&#8221;; files[1] = &#8220;c:\/b.dat&#8221;; files[2] = &#8220;c:\/c.cfg&#8221;; byte[] buf = new byte[4096]; try { ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipFileName)); for (int i=0; i&lt;files.length; i++) { FileInputStream in = new FileInputStream(files[i]); Path p = Paths.get(files[i]); String &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/www.gisdeveloper.co.kr\/?p=2221\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;[Java] File\uc5d0 \ub300\ud55c Zip \uc555\ucd95&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[60],"tags":[],"class_list":["post-2221","post","type-post","status-publish","format-standard","hentry","category-java"],"_links":{"self":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/2221","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2221"}],"version-history":[{"count":3,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/2221\/revisions"}],"predecessor-version":[{"id":10216,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/2221\/revisions\/10216"}],"wp:attachment":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2221"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2221"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2221"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}