[java]代码库
>File dir = new File("directoryName"); String children=dir.list(); if (children null) // Either dir does not exist orisnot a directory else for (int i=0; i < children.length; i++)//Get filename of file or directory String filename =children[i];//It is also possible to filter the list of returnedfiles. // Thisexample does not return any files that start with`.".FilenameFilter filter = new FilenameFilter() publicbooleanaccept(File dir, String name) return !name.startsWith(".");;children = dir.list(filter); // The list of files can alsoberetrieved as File ts File files = dir.listFiles(); // Thisfilteronly returns directories FileFilter fileFilter = newFileFilter()public boolean accept(File file) returnfile.isDirectory(); ; files= dir.listFiles(fileFilter);
File dir = new File("directoryName");String children=dir.list();if (children null) // Either dir does not exist orisnot a directory else for (int i=0; i < children.length; i++)//Get filename of file or directoryString filename =children[i];
// It is also possible to filter the list of returnedfiles.//This example does not return any files that startwith`.".FilenameFilter filter = new FilenameFilter() publicbooleanaccept(File dir, String name)return!name.startsWith(".");;children = dir.list(filter);
// The list of files can also be retrieved as File tsFile files=dir.listFiles();
// This filter only returns directoriesFileFilter fileFilter =newFileFilter() public boolean accept(File file)returnfile.isDirectory();;files = dir.listFiles(fileFilter);