J'ai un programme qui déjarre un fichier jar mais j'ai besoin de quelque chose qui déjette les fichiers récursivement. Je suis conscient qu'il ya des programmes sur le net qui peut me aider avec le même, mais je ne l'ai pas trouvé un d'entre eux travaillantUn jaring un fichier récursivement en java
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();
}
}
}
Le code ci-dessus unjars un fichier lorsqu'il fait il y a 2 pots à l'intérieur, je dois unjar ces fichiers aident aussi aprreciated.
Si oui, refactorisez simplement le code que vous avez posté afin qu'il utilise la récursivité au lieu d'une boucle while. Sinon, apprenez la récursivité. – rmcsharry