How to get all file names from a directory or folder in java
Use the method list() in java.io.File to get all file names from a directory .The file names will be in the form of name and its extension (ie xxxxx.txt).
If the Abstract path name does not denotes a directory,this method will return null.
list() method returns a String array of all file names , not the abstract path.
|String <objectName> = <fileObject>.list();|
Example to get all file names :
public static void main(String args)
File file = new File("C:\\userfile");
System.out.println("All filenames in the specified directory");
for(String names : fileNames)
All filenames in the specified directory
Nag - July 2013.xlsx
It is possible to get all the directory names that are resides in a Parent directory.
|Related Posts :|
|what is directory and how to create distinguished name for LDAP|
|What is LDAP or Lightweight Directory Access Protocol|
|Get or Set Last Modified Date and Time for a File or directory in java|
|How to find all hidden files in a folder or directory in java|
|How to create a temp file in default or specified directory|
|How to delete a file or folder from directory in java|
|How to rename a file from a directory or folder in java|