Use ZIP file system to copy, move and rename files, modify file attributes - Java File Path IO

Java examples for File Path IO:Zip File

Description

Use ZIP file system to copy, move and rename files, modify file attributes

Demo Code

import java.io.IOException;
import java.net.URI;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
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 IOException {
    Map<String, String> env = new HashMap<>();
    env.put("create", "false");
    env.put("encoding", "ISO-8859-1");
    URI uri = URI.create("jar:file:/C:/folder1/test.zip");
    try (FileSystem ZipFS = FileSystems.newFileSystem(uri, env)) {
      Path fileInZip = ZipFS.getPath("/test.png");
      Path fileOutZip = Paths.get("C:/folder1/Copy.png");
      Files.copy(fileInZip, fileOutZip);
      System.out.println("The file was successfully copied!");
    }// ww  w.j av a 2  s .  c  o m
  }
}

Related Tutorials