- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to list all files in a directory using Java?
You can get the list of files in a directory −
- Create a directory object using the File class.
- Get the list of directories in it using the getName() method.
Example
import java.io.File; public class FindingDirectories { public static void main(String args[]) { String dir ="C:/Users/Tutorialspoint/Desktop/movies"; File directory = new File(dir); File[] fileList = directory.listFiles(); for(File file: fileList) { System.out.println(file.getName()); } } }
Output
Arundhati HD.mp4 Okka Ammai Tappa.mkv Padamati Sandhya Ragam.mp4
- Related Articles
- How to list all files (only) from a directory using Java?
- Java program to List all files in a directory recursively
- How to list down all the files available in a directory using C#?
- How to read data from all files in a directory using Java?
- Java program to List all files in a directory and nested sub-directory - Recursive approach
- How to list out the hidden files in a Directory using Java program?
- How to list the hidden files in a directory in Java?
- How do I list all files of a directory in Python?
- Java program to delete all the files in a directory recursively (only files)
- C Program to list all files and sub-directories in a directory
- How to get the list of jpg files in a directory in Java?
- How to delete all files in a directory with Python?
- How to unzip all zipped files in a Linux directory?
- Java program to merge contents of all the files in a directory
- How to perform grep operation on all files in a directory?

Advertisements