首页 java基础 文件名字遍历

文件名字遍历

public static void getDirectory(String pathname) { Path path…

	public static void getDirectory(String pathname) {
		Path path = new File(pathname).toPath();
		try {
			DirectoryStream<Path> children = Files.newDirectoryStream(path);
			if (children != null) {

				for (Path child : children) {
					// System.out.println("Dir==>"+child.toAbsolutePath());

					File file = new File(child.toString());
					if(file.isDirectory()){
						System.out.println("是文件夹"+child.toString());
						getSubFile(file);

					}
					if(file.isFile()){
						System.out.println("是文件"+child.toString());
					}
				}
			}

		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	private static void getSubFile(File file) throws IOException {
		DirectoryStream<Path> twoChildren = Files.newDirectoryStream(file.toPath());
		if (twoChildren != null) {
			for (Path twoChild : twoChildren) {
				File fileTwo = new File(twoChild.toString());

				if(fileTwo.isDirectory()){
					System.out.println("是文件夹"+twoChild.toString());
					getSubFile(fileTwo);

				}
				if(fileTwo.isFile()){
					System.out.println("是文件"+twoChild.toString());
				}

			}
		}
	}

	public static void main(String[] args) {
		getDirectory("D:\\diaodutai");
	}

 

免责声明:文章内容不代表本站立场,本站不对其内容的真实性、完整性、准确性给予任何担保、暗示和承诺,仅供读者参考,文章版权归原作者所有。如本文内容影响到您的合法权益(内容、图片等),请及时联系本站,我们会及时删除处理。

为您推荐

26个大小写字母对应的哈希值

26个大小写字母对应的哈希值

大写字母: 小写字母 A 对应的哈希值:65 B 对应的哈希值:66 C 对应的哈希值:67 D 对应的哈希值:68 E...
linux 把文件名字写入到txt

linux 把文件名字写入到txt

1、首先连接上linux主机,进入到需要处理的目录,例如“/”目录。   2、输入:ls -1 > 1....
git 流程开发

git 流程开发

前提条件:不能在 master 分支上修改任何文件。master 分支的变更只能通过 git pull 和 git me...
使用Git将本地文件提交到远程仓库

使用Git将本地文件提交到远程仓库

使用Git将本地文件提交到远程仓库 使用Git将本地文件提交到远程仓库 现在要将本地代码推到git远程仓库保存,可以提交...
将博客搬至CSDN

将博客搬至CSDN

将博客搬至CSDN
返回顶部