File List() Example
Returns an array of strings naming the files and directories in the directory
File class List() method example. This example shows you how to use List method.This method Returns an array of strings naming the files and directories in the directory denoted by this abstract pathname that satisfy the specified filter.
Here is the code:-
/**
* @Program that Returns an array of strings naming the files and directories
* in the directory
* List.java
* Author:-RoseIndia Team
* Date:-30-May-2008
*/
import java.io.*;
public class List {
public static void main(String[] args) {
File f = new File("/home/girish/Desktop/g.txt");
if (f.exists()) {
String s[]=new String[1];
f.toString();
System.out.println("The files and directories in the directory are : ");
for (int i=0;i<f.length();i++)
System.out.println(s[i]);
} else {
System.out.println("File does not exists");
}
}
} |
Output of the Program
The files and directories in the directory are : null
|
|