In this video, we will see how to get list of all files/folder names from a folder in java.
public class MyMainClass {
// main method
public static void main(String[] args) {
// create a file object
String folderPath = "C:\\Users\\#JavaInspires\\Desktop\\textFolder";
File folder = new File(folderPath);
File[] files = folder.listFiles();
//iterate the files array
for(File file:files) {
//check if the file
if(file.isFile()) {
System.out.println("File - "+file.getName());
}else
if(file.isDirectory()) {
System.out.println("Folder - "+file.getName());
}
}
}
}
-----------------------------------------------------------------------------------------------------------------------------------------
read all file names in a folder java, Getting the filenames of all files in a folder, How to get list of all files/folders from a folder in Java?,List All Files In Directory, Show list of all file names from a folder.How do I get a list of filenames in a folder in java?
Download
0 formats
No download links available.
How To Get List of all Files/Folders From A Folder In Java | Java Inspires | NatokHD