Java Utililty Methods Folder Read

List of utility methods to do Folder Read

Description

The list of methods to do Folder Read are organized into topic(s).

Method

CollectiongetFiles(Collection folders)
This method recursively gets a collection of all the files in a collection of folders/files.
List<File> fileList = new LinkedList<File>();
for (File folder : folders) {
    if (folder.isDirectory()) {
        for (File f : folder.listFiles()) {
            if (f.isDirectory())
                fileList.addAll(getFiles(f));
            else
                fileList.add(f);
...
MapgetFiles(File apkFile, Pattern regex)
Returns all files in an apk that match a given regular expression.
Map<String, byte[]> files = new LinkedHashMap<>(); 
try (ZipFile apkZip = new ZipFile(apkFile)) {
    Enumeration<? extends ZipEntry> zipEntries = apkZip.entries();
    while (zipEntries.hasMoreElements()) {
        ZipEntry zipEntry = zipEntries.nextElement();
        if (regex.matcher(zipEntry.getName()).matches()) {
            try (InputStream is = new BufferedInputStream(apkZip.getInputStream(zipEntry))) {
                files.put(zipEntry.getName(), ByteStreams.toByteArray(is));
...
ListgetFiles(File archive)
Get the directory listing of a zip archive.
ZipFile zip = new ZipFile(archive);
List<String> result = new ArrayList<>(zip.size());
try {
    Enumeration<? extends ZipEntry> entries = zip.entries();
    while (entries.hasMoreElements()) {
        ZipEntry entry = entries.nextElement();
        result.add(entry.getName());
} finally {
    zip.close();
return result;
File[]getFiles(File dir)
get Files
if (!dir.isDirectory()) {
    throw new IllegalArgumentException();
Vector files = new Vector();
String[] list = dir.list();
if ((list != null) && (list.length != 0)) {
    int len = list.length;
    for (int i = 0; i < len; i++) {
...
File[]getFiles(File dir)
Recursively gets all the files in a directory
List<File> list = new LinkedList<File>();
getAllFilesRecursively(dir, list);
File[] arr = new File[list.size()];
list.toArray(arr);
return arr;
File[]getFiles(File dir)
get Files
if (dir.isFile())
    throw new IOException("BadInputException: not a directory.");
if (!dir.exists()) {
    throw new IOException(" don't exist ");
File[] files = dir.listFiles();
return files;
ListgetFiles(File dir, File... excludes)
get Files
List<String> result = new ArrayList<String>();
File[] aFiles = dir.listFiles();
List<File> files = Arrays.asList(aFiles);
for (File file : files) {
    boolean exclude = false;
    for (File f : excludes) {
        if (file.getAbsolutePath().startsWith(f.getAbsolutePath())) {
            exclude = true;
...
ListgetFiles(File dir, final String pattern)
get Files
return getFiles(dir, pattern, null);
StringgetFiles(File dir, String... names)
get Files
StringBuilder builder = new StringBuilder();
File[] files = dir.listFiles();
if (files != null) {
    if (names.length > 0) {
        for (File file : files) {
            for (String name : names) {
                if (file.getName().startsWith(name)) {
                    append(file.getPath(), builder);
...
File[]getFiles(File directory)
Get the list of files from a given directory
if (directory == null || !directory.isDirectory()) {
    return null;
return directory.listFiles();