Last active
August 29, 2015 14:01
-
-
Save mh61503891/6310693c3efad439b71a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.File; | |
import java.io.IOException; | |
import java.nio.file.Files; | |
import java.nio.file.Path; | |
import java.nio.file.Paths; | |
import java.util.Arrays; | |
import java.util.HashSet; | |
import java.util.Set; | |
import java.util.stream.Collectors; | |
import org.apache.commons.io.FilenameUtils; | |
public class Test { | |
static Set<String> get1(File root) { | |
Set<String> names = new HashSet<>(); | |
for (File file : root.listFiles()) | |
if (FilenameUtils.isExtension(file.getPath(), Arrays.asList("jar", "war", "zip"))) | |
names.add(FilenameUtils.getBaseName(file.getPath())); | |
return names; | |
} | |
static Set<String> get2(Path root) throws IOException { | |
return Files.list(root). | |
filter(path -> FilenameUtils.isExtension(path.toFile().getPath(), Arrays.asList("jar", "war", "zip"))). | |
map(path -> FilenameUtils.getBaseName(path.toFile().getPath())). | |
collect(Collectors.toSet()); | |
} | |
public static void main(String[] args) throws IOException { | |
System.err.println(get1(new File("lib"))); | |
System.err.println(get2(Paths.get("lib"))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment