The list() method of File class is used to get the list of file names in the folder or directory.
Example:
package com.w3spoint; import java.io.File; public class ListFileNames { public static void main(String args[]){ File file = new File("D:/Test files/"); String[] fileList = file.list(); for(String name:fileList){ System.out.println(name); } } } |
Output:
file1.docx file2.docx newTest.txt |
Please follow and like us: