|
List Files
The following example shows how to list the file of a given directory.
|
package com.bethecoder.tutorials.io;
import java.io.File;
public class ListFilesTest {
/**
* @param args
*/
public static void main(String[] args) {
File directory = new File("C:\\NEW");
File [] filesInDir = directory.listFiles();
System.out.println("Directory file listing of " + directory);
for (int i = 0 ; i < filesInDir.length ; i ++) {
System.out.println(filesInDir[i]);
}
}
}
|
| |
It gives the following output,
Directory file listing of C:\NEW
C:\NEW\BIOSinfo.log
C:\NEW\file_ops.txt
C:\NEW\IPC.LOG
C:\NEW\NEW_SUB
C:\NEW\readonly_file.txt
C:\NEW\software.tsv
C:\NEW\test.txt
|
|