java.io.FilelistFiles
public File[] listFiles()
Returns an array of abstract pathnames denoting the files in the directory denoted by this abstract pathname. 
If this abstract pathname does not denote a directory, then this method returns null. Otherwise an array of File objects is returned, one for each file or directory in the directory. Pathnames denoting the directory itself and the directory's parent directory are not included in the result. Each resulting abstract pathname is constructed from this abstract pathname using the File(File, String) constructor. Therefore if this pathname is absolute then each resulting pathname is absolute; if this pathname is relative then each resulting pathname will be relative to the same directory. There is no guarantee that the name strings in the resulting array will appear in any specific order; they are not, in particular, guaranteed to appear in alphabetical order. 
Returns:
An array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname. The array will be empty if the directory is empty. Returns null if this abstract pathname does not denote a directory, or if an I/O error occurs. 
Throws: 
SecurityException - If a security manager exists and its SecurityManager.checkRead(java.lang.String) method denies read access to the directory
Since: 
1.2 然后遍历数组,分析FileName,把后缀为.wav的文件都打印出来

解决方案 »

  1.   

    public void listPath(File dir) throws Exception{
    File[ ] entries = dir.listFiles( );
    int sz = entries.length;
    String path="";

    for(int i=0; i<sz; i++) {
    if(entries[i].isDirectory()){
    path=entries[i].getAbsolutePath();
    listPath(entries[i]);
    count++;
    }
    else
    {
    path=entries[i].getAbsolutePath();
    if(path.endsWith("wav"))
    {
    System.out.println("找到.wav文件:"+path);
    }
    count++;
    }

    }    }
      

  2.   

    谢谢,稍后为各位加分。是不是还有种处理方式:
    list(FilenameFilter filter)
    listFiles(FileFilter filter)

      

  3.   

    /**这个是我以前用过的,作了一点修改,打印出符合条件的文件名列表。希望会有帮助。
    */
    import java.io.*;
    import java.util.*;public class TryFileNames
    {
    private static String myPath = "e:\\tmp\\";
    public static void main(String args[])
    {
    ExtensionFilter myFilter= new ExtensionFilter("wav"); 
    String[] resultNames;
    File searchFilePath;

    searchFilePath = new File(myPath);
    resultNames= getFilePath.list(myFilter);
    for(int i=0;i<resultNames.length;i++)
    {
    System.out.println("the existing file "+i+" is: "+ resultNames[i]);
    }
    }//end main
    }//end public class
    class ExtensionFilter implements FilenameFilter
    {
    private String extension;
    public ExtensionFilter(String endStr)
    {
    extension = "."+endStr;
    }
    public boolean accept(File dir, String name)
    {
    return name.endsWith(extension);
    }
    }//end inner class