循环遍历文件夹,获取指定文件夹名字的路径

public static String getResPath(String filePath) {
		File file = FileUtils.getFile(filePath);
		if (!file.exists() || !file.isDirectory())
			return null;
		File[] list = file.listFiles(new FilenameFilter() {
			@Override
			public boolean accept(File dir, String name) {
				if (dir.isDirectory() && "res".equals(name))
					return true;
				return false;
			}
		});
		if (list != null && list.length > 0) {
			return list[0].getAbsolutePath();
		}
		File[] list2 = file.listFiles();
		if(list2!=null)
		for (File innerFilePath : list2) {
			String resPath = getResPath(innerFilePath.getAbsolutePath());
			if (resPath != null) {
				return resPath;
			}
		}
		return null;
	}

获取文件夹为res的路径

猜你喜欢

转载自blog.csdn.net/weixin_41796956/article/details/82965043
今日推荐