How to Scan All Mp3 Files In the Given Directory using Java? Last Updated : 28 Apr, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report In this article, we will discuss how to scan all mp3 files and not only from a specific path for an android media player. We will use a recursive method for scanning files. Scan all folders and sort out all mp3 files using the File and FileFilter class. Implementation Java import java.io.File; import java.io.FileFilter; // Java program for scan all mp3 files in given directory public class Main { public static final String C_DIRECTORY = "C:\\"; public static void main(String[] args) { scanAllFile(C_DIRECTORY); } // recursive function for scan all files in directory public static void scanAllFile(String path) { File file = new File(path); File[] files = file.listFiles(); if (files == null) return; for (File f : files) { if (f.isDirectory() && f.exists()) { try { scanAllFile(f.getPath()); } catch (Exception e) { e.printStackTrace(); continue; } } else if (!f.isDirectory() && f.exists()) { // using file filter if (filter.accept(f)) { System.out.println(f.getName()); } } } } // file filter for sort mp3 files static FileFilter filter = new FileFilter() { @Override public boolean accept(File file) { if (file.getName().endsWith(".mp3") || file.getName().endsWith(".mp3")) { return true; } return false; } }; } Output:break.mp3 error.mp3 foldedAreas.mp3 quickFixes.mp3 taskEnded.mp3 terminalBell.mp3 warning.mp3 house_lo.mp3 Comment More infoAdvertise with us Next Article How to find and open the Hidden files in a Directory using Java V vaibhavshelke12 Follow Improve Article Tags : Java Technical Scripter Technical Scripter 2022 Practice Tags : Java Similar Reads How to find and open the Hidden files in a Directory using Java Pre-requisites: Java File Handling So far the operations using Java programs are done on a prompt/terminal which is not stored anywhere. But in the software industry, most of the programs are written to store the information fetched from the program. One such way is to store the fetched information 3 min read How to print all files within a directory using Python? The OS module is one of the most popular Python modules for automating the systems calls and operations of an operating system. With a rich set of methods and an easy-to-use API, the OS module is one of the standard packages and comes pre-installed with Python. In this article, we will learn how to 3 min read How to play an Audio file using Java In this article we will see, how can we play an audio file in pure java, here pure means, we are not going to use any external library. You can create your own music player by the help of this article. Java inbuilt libraries support only AIFC, AIFF, AU, SND and WAVE formats. There are 2 different in 4 min read Moving a file from one directory to another using Java Java provides functions to move files between directories. Two ways to achieve this are described here. The first method utilizes Files package for moving while the other method first copies the file to destination and then deletes the original copy from the source. Using Files.Path move() method: R 2 min read How to rename all files of a folder using Java? When transferring files from the camera folder to a workspace where we would like to analyze the pictures, it becomes difficult to deal with long files and type them out again and again when testing them through code. Also, the number of files might be too large to manually rename each one of them. 4 min read How to Check a File or Directory Exists in Java? One of the most frequent tasks carried out by a file system in an operating system is checking the existence of a directory or a file. In the form of library functions, most programming languages provide some level of file system accessibility. You will discover how to test an existing file or direc 1 min read Like