save list of file to a directory java code example
Example 1: how to get all the names of the files in a folder in java?
List<String> results = new ArrayList<String>();
File[] files = new File("/path/to/the/directory").listFiles();
for (File file : files) {
if (file.isFile()) {
results.add(file.getName());
}
}
Example 2: java list all non directory files in the directory
public class Pathnames {
public static void main(String[] args) {
String[] pathnames;
File f = new File("D:/Programming");
pathnames = f.list();
for (String pathname : pathnames) {
System.out.println(pathname);
}
}
}