COMPUTER LANGUAGES HTML,C,C++.JAVA,.NET AND MULTIMEDIA basics and programs click home button
JAVA EXAMPLES DISPLAY IN A DIRECTORY
Java Examples - Display files in a directory
Problem Description:
How to display all the files in a directory ?
Solution:
Following example shows how to display all the filess contained in a directory using list method of File class.
import java.io.*;
class Main {
public static void main(String[] args) {
File dir = new File("C:");
String[] children = dir.list();
if (children == null) {
System.out.println( "Either dir does
not exist or is not a directory");
}
else {
for (int i=0; i< children.length; i++) {
String filename = children[i];
System.out.println(filename);
}
}
}
}
Result:
The above code sample will produce the following result.
build
build.xml
destnfile
detnfile
filename
manifest.mf
nbproject
outfilename
src
srcfile
test