Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/354.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在java中递归地解除文件jar_Java_Io - Fatal编程技术网

在java中递归地解除文件jar

在java中递归地解除文件jar,java,io,Java,Io,我有一个取消jar文件的程序,但我需要一些递归取消jar文件的东西。我知道网上有一些程序可以帮助我做同样的事情,但我还没有发现其中任何一个能起作用 try (JarArchiveInputStream jarArchiveInputStreamOuter = new JarArchiveInputStream( sftpChannel.get(lsEntry.getFilename(), new ProgressMonitor()))) { JarArchiveEntry ja

我有一个取消jar文件的程序,但我需要一些递归取消jar文件的东西。我知道网上有一些程序可以帮助我做同样的事情,但我还没有发现其中任何一个能起作用

try (JarArchiveInputStream jarArchiveInputStreamOuter = new JarArchiveInputStream(
    sftpChannel.get(lsEntry.getFilename(), new ProgressMonitor()))) {

    JarArchiveEntry jarEntry = jarArchiveInputStreamOuter.getNextJarEntry();

    System.out.println("What is the jarEntry " + jarEntry);

    while (jarEntry != null) {

        if (jarEntry.isDirectory()) {
            jarEntry = jarArchiveInputStreamOuter.getNextJarEntry();
            continue;
        }

        File currentFile = new File(destinationDirectory, jarEntry.getName());
        File parent = currentFile.getParentFile();
        if (!parent.exists()) {
            parent.mkdirs();
        }

        try (OutputStream outPutStream = new FileOutputStream(currentFile)) {
            Instant start = Instant.now();
            System.out.println("Start time is " + start);
            IOUtils.copy(jarArchiveInputStreamOuter, outPutStream);
            Instant end = Instant.now();
            System.out.println("End time is " + end);
            System.out.println(Duration.between(start, end));
            jarEntry = jarArchiveInputStreamOuter.getNextJarEntry();
        }
    }
}

上面的代码取消锁定一个文件完成后,其中有2个JAR,我需要取消锁定这些文件。如果您使用Java 7或更高版本,您应该检查新的API以了解更多信息。它允许使用jar/zip,就像处理普通文件/文件夹一样

Path jarPath = Paths.get([path of the jar]);
URI jarUri = URI.create("jar:" + jarPath.toUri());      
Filesystem jarSystem = FileSystems.newFileSystem(jarUri, new HashMap<String,String>());
Path-jarPath=Path.get([jar的路径]);
URI jarUri=URI.create(“jar:+jarPath.toUri());
Filesystem jarSystem=FileSystems.newFileSystem(jarUri,newhashmap());

之后,您可以使用、类和方法在jar中工作,就像在普通文件/文件夹中一样

您知道如何在Java中进行递归吗?如果是,那么只需重构您发布的代码,使其使用递归而不是while循环。否则,学习递归。这是一个动态的jar,我不确定上面的方法是否有效。
Path jarPath = Paths.get([path of the jar]);
URI jarUri = URI.create("jar:" + jarPath.toUri());      
Filesystem jarSystem = FileSystems.newFileSystem(jarUri, new HashMap<String,String>());