跨平台ZIP文件系统

时间:2013-12-09 18:02:54

标签: java filesystems zip nio

我发现这个示例类在Java中使用ZIP文件系统。如何在跨平台中使用它,我必须从OSX运行该程序,并且需要在Windows机器中创建ZIP文件。

public class ZipFSPUser {
    public static void main(String [] args) throws Throwable {
        Map<String, String> env = new HashMap<>(); 
        env.put("create", "true");
        // locate file system by using the syntax 
        // defined in java.net.JarURLConnection
        URI uri = URI.create("jar:file://windowsIpAddress/zipfs/zipfstest.zip");

       try (FileSystem zipfs = FileSystems.newFileSystem(uri, env)) {
            Path externalTxtFile = Paths.get("/Users/myself/zipfs/SomeTextFile.txt");
            Path pathInZipfile = zipfs.getPath("/SomeTextFile.txt");          
            // copy a file into the zip file
            Files.copy( externalTxtFile,pathInZipfile, 
                    StandardCopyOption.REPLACE_EXISTING ); 
        } 
    }
}

现在这在Windows机器上工作正常,但是当我尝试从我的Mac机器执行此操作时,我收到错误:

java.lang.IllegalArgumentException: URI has an authority component

我尝试了URI,jar:file://usrName:pwd@windowsIpAddress/zipfs/zipfstest.zipjar:http://windowsIpAddress/zipfs/zipfstest.zip,但没有运气。

0 个答案:

没有答案