小编ilo*_*ing的帖子

如何在Java中递归查找文件?

我想知道如何编写一个递归程序来查找由起始路径指示的Java文件.它应该在树中搜索指定的文件.如果找到该文件,则应返回该文件的位置.这是我到目前为止(不多,仍然需要基本的清理).我需要使用这些确切的方法.我大多混淆了什么方法.所以我知道我需要使用:

File f = new File(dirName);

String [] fileList = f.list();

File aFile = new File (dirName + "\\" + fileList[i]);

if (aFile.isDirectory()) {...}

public class FindFile {
Run Code Online (Sandbox Code Playgroud)

如果你能帮我弄清楚每种方法的用途,那将是一个惊人的帮助!我只是不太了解每种方法的逻辑.我还有一个我需要使用的另一个类的驱动程序.

/**
 * This constructor accepts the maximum number of files to find.
 */
public FindFile (int maxFiles)
{
}

/**
 * The parameters are the target file name to look for and the directory to start in.
 * @param  target = target file name, dirName = directory to start in
 */ …
Run Code Online (Sandbox Code Playgroud)

java recursion

3
推荐指数
2
解决办法
9298
查看次数

标签 统计

java ×1

recursion ×1