forked from patniemeyer/learningjava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZipTest.java
More file actions
34 lines (30 loc) · 1.06 KB
/
Copy pathZipTest.java
File metadata and controls
34 lines (30 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import java.io.*;
import java.net.URI;
import java.nio.file.*;
import java.util.*;
public class ZipTest
{
public static void main( String[] args ) throws IOException
{
// Construct the URI pointing to the ZIP archive
URI fsURI = URI.create("jar:file:/Users/pat/tmp/MyArchive.zip");
// Open or creat it and write a file
Map<String, String> env = new HashMap<>();
//env.put("create", "true");
try ( FileSystem zipfs = FileSystems.newFileSystem( fsURI, env ) )
{
Path path = zipfs.getPath("/README.txt");
OutputStream out = Files.newOutputStream( path );
try ( PrintWriter pw = new PrintWriter( new OutputStreamWriter( out ) ) ) {
pw.println("Hello World!");
}
}
// Move the file
try ( FileSystem zipfs = FileSystems.newFileSystem( fsURI, env ) )
{
Path path = zipfs.getPath("/README.txt");
Path toPath = zipfs.getPath( "/README2.txt" );
Files.move( path, toPath );
}
}
}