so I'm learning java right now and have seen numerous examples of this same question, but the answers mostly have to do with Android permissions people needed to add. In my case, I have tested that my program has access to the given directory. The System.out's print out Arrays with all of the files and directories in it, but for some reason the files variable finds that fileList is null. Thanks in advance
package com.assignment3;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
public class FileFinder {
ArrayList<String> folders = new ArrayList<>();
public void find(ArrayList<String> args){
if (args.size() > 0){
File file = new File(args.get(0));
System.out.println(file);
String[] fileList = file.list();
assert fileList != null;
String[] files = new String[fileList.length - 1];
if (files.length - 1 >= 0) System.arraycopy(fileList, 0, files, 0, files.length - 1);
System.out.println(Arrays.toString(file.list()));
System.out.println(Arrays.asList(files));
for (String f : fileList){
int ext = f.lastIndexOf(".");
if (ext > 0){
System.out.println(f);
} else {
folders.add(f);
}
}
if (folders.size() > 0){
find(folders);
folders.remove(0);
} else {
System.out.println("All files listed.");
}
} else {
System.out.println("You need to add a directory to command line arguments.");
System.exit(0);
}
}
}