`
yuxuguang
  • 浏览: 136828 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

读取文件夹下所有文件

    博客分类:
  • java
 
阅读更多
/**
	 * 读取文件夹下所有文件
	 */
	private List readfile(String filepath) throws FileNotFoundException,
			IOException {
		List fileNameList = new ArrayList();
		try {
			File file = new File(filepath);
			if (!file.isDirectory()) {
				fileNameList.add(file.getName());
			} else if (file.isDirectory()) {
				String[] filelist = file.list();
				for (int i = 0; i < filelist.length; i++) {
					File readfile = new File(filepath + "\\" + filelist[i]);
					if (!readfile.isDirectory()) {
						fileNameList.add(readfile.getName());
					} else if (readfile.isDirectory()) {
						readfile(filepath + "\\" + filelist[i]);
					}
				}

			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			System.out.println("readfile()   Exception:" + e.getMessage());
		}
		return fileNameList;
	}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics