How do I get a listing of the files in a directory?

John Zukowski

Create a java.io.File for the directory, then ask for the list of files with one of the following:

public java.lang.String[] list();
public java.lang.String[] list(java.io.FilenameFilter);
public java.io.File[] listFiles();
public java.io.File[] listFiles(java.io.FilenameFilter);
public java.io.File[] listFiles(java.io.FileFilter);
The first two return the filenames as strings (for that directory), the latter three return actual File objects.

Also, see Re: how do i search a file from a folder that is in the server side using servlet for another method that lists files in a directory.

0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact