这里面包含了一百多个JAVA源文件

源代码在线查看: e031. listing the files or subdirectories in a directory.txt

软件大小: 551 K
上传用户: maple_78
关键词: JAVA
下载地址: 免注册下载 普通下载 VIP

相关代码

				This example lists the files and subdirectories in a directory. To list all descendant files and subdirectories under a directory, see e33 Traversing the Files and Directories Under a Directory. 
				    File dir = new File("directoryName");
				    
				    String[] children = dir.list();
				    if (children == null) {
				        // Either dir does not exist or is not a directory
				    } else {
				        for (int i=0; i				            // Get filename of file or directory
				            String filename = children[i];
				        }
				    }
				    
				    // It is also possible to filter the list of returned files.
				    // This example does not return any files that start with `.'.
				    FilenameFilter filter = new FilenameFilter() {
				        public boolean accept(File dir, String name) {
				            return !name.startsWith(".");
				        }
				    };
				    children = dir.list(filter);
				    
				    
				    // The list of files can also be retrieved as File objects
				    File[] files = dir.listFiles();
				    
				    // This filter only returns directories
				    FileFilter fileFilter = new FileFilter() {
				        public boolean accept(File file) {
				            return file.isDirectory();
				        }
				    };
				    files = dir.listFiles(fileFilter);
				
				 Related Examples 
				
							

相关资源