0% found this document useful (0 votes)
7 views1 page

Java Program to List Directory Files

The document provides a Java program that lists all files in a specified directory, including those in its subdirectories. It uses the 'File' class to navigate through the directory structure and prints the paths of both files and directories. The program handles potential IOExceptions during file access.

Uploaded by

abhigzna.abs
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

Java Program to List Directory Files

The document provides a Java program that lists all files in a specified directory, including those in its subdirectories. It uses the 'File' class to navigate through the directory structure and prints the paths of both files and directories. The program handles potential IOExceptions during file access.

Uploaded by

abhigzna.abs
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

EXPERIMENT-13

13. Write a Java program to list all the files in a directory including the files present in all
its sub directories.

Program:-

import [Link].*;
public class FileDisplay
{
public static void main(String args[])
{
File DirName=new File("C:\\Users");
displayContents(DirName);
}
public static void displayContents(File dir)
{
try{
File[] list=[Link]();
for(File file:list)
{
if([Link]())
{
[Link]("directory:"+[Link]());
displayContents(file);
}
else
{
[Link]("file:"+[Link]());
}
}
}
catch(IOException ie)
{
[Link]();
}
}
}

You might also like