Java File Find find(final File root, final String name)

Here you can find the source of find(final File root, final String name)

Description

find

License

Open Source License

Parameter

Parameter Description
root a parameter
name a parameter

Return

File

Declaration

public static File find(final File root, final String name) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Manchester Institute of Biotechnology
 * University of Manchester/*  w  w w .  ja va  2s.co  m*/
 * Manchester M1 7ND
 * United Kingdom
 * 
 * Copyright (C) 2013 University of Manchester
 * 
 * This program is released under the Academic Free License ("AFL") v3.0.
 * (http://www.opensource.org/licenses/academic.php)
 *******************************************************************************/

import java.io.*;

public class Main {
    /**
     * 
     * @param root
     * @param name
     * @return File
     */
    public static File find(final File root, final String name) {
        if (root.getName().equals(name)) {
            return root;
        }

        if (root.isDirectory()) {
            for (final File child : root.listFiles()) {
                final File result = find(child, name);

                if (result != null) {
                    return result;
                }
            }
        }

        return null;
    }
}

Related

  1. find(File file, Pattern pattern, int limit, List found, Set visited)
  2. find(File folder, final String name)
  3. find(File path, Boolean recursive)
  4. find(File root)
  5. find(final File fileDir, final String fileNameRegex)
  6. find(String _sSourceString, String _sReg, int group)
  7. find(String executable, File... dirs)
  8. find(String name, File dir)
  9. find(String path, String matcher)