Folder Explorer in Java with Source Code

Here is a simple implementation of a folder explorer in Java:

import java.util.Scanner;

public class FolderExplorer {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(;
        System.out.print("Enter folder path: ");
        String folderPath = scanner.nextLine();
        File folder = new File(folderPath);

        if (!folder.exists()) {
            System.out.println("Folder does not exist.");

        if (!folder.isDirectory()) {
            System.out.println("Path is not a directory.");

        System.out.println("Folder contents:");
        File[] files = folder.listFiles();
        for (File file : files) {

This program takes a folder path as input from the user, checks if the folder exists and is a directory, and then prints the contents of the folder. The listFiles() method of the File class is used to obtain an array of File objects representing the files and directories in the specified folder. The names of the files and directories are then printed using a for-each loop.

Note that this implementation only works for a single folder and does not traverse subdirectories.

I hope this helps!