{"id":1466,"date":"2012-07-24T12:42:02","date_gmt":"2012-07-24T10:42:02","guid":{"rendered":"http:\/\/www.tutego.de\/blog\/javainsel\/?p=1466"},"modified":"2012-07-24T12:42:02","modified_gmt":"2012-07-24T10:42:02","slug":"how-to-put-files-in-a-zip-file-with-nio-2","status":"publish","type":"post","link":"https:\/\/www.tutego.de\/blog\/javainsel\/2012\/07\/how-to-put-files-in-a-zip-file-with-nio-2\/","title":{"rendered":"How to put files in a ZIP file with NIO.2"},"content":{"rendered":"<pre class=\"csharpcode\">URI p = Paths.get( <span class=\"str\">&quot;c:\/Users\/Christian\/Dropbox\/jokes.zip&quot;<\/span> ).toUri();\nURI uri = URI.create( <span class=\"str\">&quot;jar:&quot;<\/span> + p );\n\nMap&lt;String, String&gt; env = <span class=\"kwrd\">new<\/span> HashMap&lt;&gt;();\nenv.put( <span class=\"str\">&quot;create&quot;<\/span>, <span class=\"str\">&quot;true&quot;<\/span> );\n<span class=\"kwrd\">try<\/span> ( FileSystem zipfs = FileSystems.newFileSystem( uri, env ) ) {\n  Files.write( zipfs.getPath( <span class=\"str\">&quot;\/j1.txt&quot;<\/span> ), <span class=\"str\">&quot;The truth is out there. Anybody got the URL?&quot;<\/span>.getBytes() );\n  Files.write( zipfs.getPath( <span class=\"str\">&quot;\/j2.txt&quot;<\/span> ), <span class=\"str\">&quot;The more I C, the less I see.&quot;<\/span>.getBytes() );\n}<\/pre>\n<style type=\"text\/css\">\n.csharpcode, .csharpcode pre\n{\n\tfont-size: small;\n\tcolor: black;\n\tfont-family: consolas, \"Courier New\", courier, monospace;\n\tbackground-color: #ffffff;\n\t\/*white-space: pre;*\/\n}\n.csharpcode pre { margin: 0em; }\n.csharpcode .rem { color: #008000; }\n.csharpcode .kwrd { color: #0000ff; }\n.csharpcode .str { color: #006080; }\n.csharpcode .op { color: #0000c0; }\n.csharpcode .preproc { color: #cc6633; }\n.csharpcode .asp { background-color: #ffff00; }\n.csharpcode .html { color: #800000; }\n.csharpcode .attr { color: #ff0000; }\n.csharpcode .alt \n{\n\tbackground-color: #f4f4f4;\n\twidth: 100%;\n\tmargin: 0em;\n}\n.csharpcode .lnum { color: #606060; }<\/style>\n","protected":false},"excerpt":{"rendered":"<p>URI p = Paths.get( &quot;c:\/Users\/Christian\/Dropbox\/jokes.zip&quot; ).toUri(); URI uri = URI.create( &quot;jar:&quot; + p ); Map&lt;String, String&gt; env = new HashMap&lt;&gt;(); env.put( &quot;create&quot;, &quot;true&quot; ); try ( FileSystem zipfs = FileSystems.newFileSystem( uri, env ) ) { Files.write( zipfs.getPath( &quot;\/j1.txt&quot; ), &quot;The truth is out there. Anybody got the URL?&quot;.getBytes() ); Files.write( zipfs.getPath( &quot;\/j2.txt&quot; ), &quot;The more [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","_links_to":"","_links_to_target":""},"categories":[5,68],"tags":[],"class_list":["post-1466","post","type-post","status-publish","format-standard","hentry","category-java-7","category-snippet"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.tutego.de\/blog\/javainsel\/wp-json\/wp\/v2\/posts\/1466","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tutego.de\/blog\/javainsel\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tutego.de\/blog\/javainsel\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tutego.de\/blog\/javainsel\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tutego.de\/blog\/javainsel\/wp-json\/wp\/v2\/comments?post=1466"}],"version-history":[{"count":1,"href":"https:\/\/www.tutego.de\/blog\/javainsel\/wp-json\/wp\/v2\/posts\/1466\/revisions"}],"predecessor-version":[{"id":1467,"href":"https:\/\/www.tutego.de\/blog\/javainsel\/wp-json\/wp\/v2\/posts\/1466\/revisions\/1467"}],"wp:attachment":[{"href":"https:\/\/www.tutego.de\/blog\/javainsel\/wp-json\/wp\/v2\/media?parent=1466"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tutego.de\/blog\/javainsel\/wp-json\/wp\/v2\/categories?post=1466"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tutego.de\/blog\/javainsel\/wp-json\/wp\/v2\/tags?post=1466"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}