---
title: 'How to put files in a ZIP file with NIO.2'
url: 'https://tutego.de/blog/javainsel/2012/07/how-to-put-files-in-a-zip-file-with-nio-2'
markdown: 'https://tutego.de/blog/javainsel/2012/07/how-to-put-files-in-a-zip-file-with-nio-2.md'
date: '2012-07-24'
description: 'URI p = Paths.get( "c:/Users/Christian/Dropbox/jokes.zip" ).toUri(); URI uri = URI.create( "jar:" + p ); Map env = new HashMap(); env.put( "create", "true" ); try ( FileSystem zipfs = FileSystems.newFileSystem( uri, env ) ) { Files.write( zipfs.getPath( "/j1.txt" ), "The truth is out there. Anyb…'
taxonomy:
  category:
    - 'Java 7'
    - Snippet
---

# How to put files in a ZIP file with NIO.2

![Illustration einer tropischen Insel mit Palmen und einem hohen Berg](https://tutego.de/blog/javainsel/user/themes/tutego/images/insel-cover.jpg)# Java Blog für Programmierer

[Java Blog für Programmierer](https://tutego.de/blog/javainsel/)

## How to put files in a ZIP file with NIO.2

24.07.2012 · [Christian Ullenboom](https://tutego.de/blog/javainsel/author/admin/)

 ```java
URI p = Paths.get( "c:/Users/Christian/Dropbox/jokes.zip" ).toUri();
URI uri = URI.create( "jar:" + p );

Map env = new HashMap();
env.put( "create", "true" );
try ( FileSystem zipfs = FileSystems.newFileSystem( uri, env ) ) {
  Files.write( zipfs.getPath( "/j1.txt" ), "The truth is out there. Anybody got the URL?".getBytes() );
  Files.write( zipfs.getPath( "/j2.txt" ), "The more I C, the less I see.".getBytes() );
}
```

Kategorien: [Java 7](https://tutego.de/blog/javainsel/category/java-7/), [Snippet](https://tutego.de/blog/javainsel/category/snippet/)

## 1 Kommentare

**Ana Zerpa** · [16.07.2015 12:50](#comment-96512)

Using this method, java throws me this exception: Exception in thread "main" java.util.zip.ZipError: zip END header not found at com.sun.nio.zipfs.ZipFileSystem.zerror(ZipFileSystem.java:1605) at com.sun.nio.zipfs.ZipFileSystem.findEND(ZipFileSystem.java:1021) at com.sun.nio.zipfs.ZipFileSystem.initCEN(ZipFileSystem.java:1030) at com.sun.nio.zipfs.ZipFileSystem.(ZipFileSystem.java:130) at com.sun.nio.zipfs.ZipFileSystemProvider.newFileSystem(ZipFileSystemProvider.java:117) at java.nio.file.FileSystems.newFileSystem(Unknown Source) at java.nio.file.FileSystems.newFileSystem(Unknown Source) at Tests.main(Tests.java:72) Any ideas of what may be causing it? Thanks in adavance for the help

Die bisherigen Kommentare wurden aus WordPress übernommen. Neue Kommentare sind derzeit geschlossen.

[← Alle Beiträge](https://tutego.de/blog/javainsel/)

---

## Navigation

- Previous: [Designfrage: Wie nutzt man GWT-RPC-Aufrufe lokal etwa bei Offline-Anwendungen?](https://tutego.de/blog/javainsel/2012/07/designfrage-wie-nutzt-man-gwt-rpc-aufrufe-lokal.md)
- Next: [Arrays.asList() Beispiel und Hinweis](https://tutego.de/blog/javainsel/2012/07/arrays-aslist-beispiel-und-hinweis.md)
