Skip to content

Instantly share code, notes, and snippets.

@mh61503891
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mh61503891/6310693c3efad439b71a to your computer and use it in GitHub Desktop.
Save mh61503891/6310693c3efad439b71a to your computer and use it in GitHub Desktop.
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