package pl.etroya.corejava.ioStreamsAndFiles;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;

public class Main {
    public static void main(String[] args) throws URISyntaxException, IOException {
        String[] data = {
                "Line 1",
                "Line 2 2",
                "Line 3 3 3"
        };

        FileSystem zipFs = openZip(Paths.get("testData.zip"));
    }

    private static FileSystem openZip(Path zipPath) throws URISyntaxException, IOException {
        Map<String, String> providerProps = new HashMap<>();
        providerProps.put("create", "true");

        URI zipUri = new URI("jar:file", zipPath.toUri().getPath(), null);
        FileSystem zipFs = FileSystems.newFileSystem(zipUri, providerProps);
        return zipFs;

    }

    private static void copyToZim(FileSystem zipFs) {

    }
}

@@ -40,16 +40,47 @@
 Files;%0A%0A
+import java.io.BufferedWriter;%0A
 import j
@@ -91,32 +91,32 @@
 io.IOException;%0A
-
 import java.net.
@@ -176,57 +176,23 @@
 nio.
-file.FileSystem;%0Aimport java.nio.file.FileSystems
+charset.Charset
 ;%0Aim
@@ -210,20 +210,17 @@
 io.file.
-Path
+*
 ;%0Aimport
@@ -229,21 +229,18 @@
 ava.
-nio.file.Path
+util.Array
 s;%0Ai
@@ -512,32 +512,36 @@
     %7D;%0A%0A        
+try(
 FileSystem zipFs
@@ -577,17 +577,324 @@
 a.zip%22))
-;
+)%7B%0A            copyToZip(zipFs);%0A            writeToFileInZip1(zipFs, data); //copy file to ZIP traditionally%0A            writeToFileInZip2(zipFs, data); //copy file to ZIP new way%0A        %7D catch (Exception e)%7B%0A            System.out.println(e.getClass().getSimpleName() + %22 - %22 + e.getMessage());%0A        %7D
 %0A    %7D%0A%0A
@@ -1311,30 +1311,861 @@
 ToZi
-m(FileSystem zipFs) %7B%0A
+p(FileSystem zipFs) throws IOException %7B%0A        Path sourceFile = Paths.get(%22file.txt%22);%0A        //Path sourceFile = FileSystems.getDefault().getPath(%22file.txt);%0A        Path destFile = zipFs.getPath(%22/fileCopied.txt%22);%0A%0A        Files.copy(sourceFile, destFile, StandardCopyOption.REPLACE_EXISTING);%0A%0A    %7D%0A%0A    private static void writeToFileInZip1(FileSystem zipFs, String%5B%5D data) throws IOException %7B%0A        try(BufferedWriter writer = Files.newBufferedWriter(zipFs.getPath(%22/newFile1.txt%22))) %7B%0A            for(String d:data)%7B%0A                writer.write(d);%0A                writer.newLine();%0A            %7D%0A%0A        %7D%0A    %7D%0A%0A    private static void writeToFileInZip2(FileSystem zipFs, String%5B%5D data) throws IOException %7B%0A        Files.write(zipFs.getPath(%22/newFile2.txt%22), Arrays.asList(data), Charset.defaultCharset(), StandardOpenOption.CREATE);
 %0A   

write files to zip in different way