Java File Find findByFileName(List files, String fileName)

Here you can find the source of findByFileName(List files, String fileName)

Description

find By File Name

License

LGPL

Declaration

public static File findByFileName(List<File> files, String fileName) throws FileNotFoundException 

Method Source Code


//package com.java2s;
/*/*ww  w .  jav  a2s  . c om*/
 GNU LESSER GENERAL PUBLIC LICENSE
 Version 3, 29 June 2007
    
 Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
 Everyone is permitted to copy and distribute verbatim copies
 of this license document, but changing it is not allowed.
    
    
 This version of the GNU Lesser General Public License incorporates
 the terms and conditions of version 3 of the GNU General Public
 License
 */

import java.io.File;

import java.io.FileNotFoundException;

import java.util.List;

public class Main {
    public static File findByFileName(List<File> files, String fileName) throws FileNotFoundException {
        for (File itFile : files) {
            if (itFile.getName().equals(fileName)) {
                return itFile;
            }
        }
        throw new FileNotFoundException("The file name " + fileName + " doesn't exist");
    }
}

Related

  1. find(String path, String matcher)
  2. find(String path, String suffix)
  3. find2(File baseDir, FileFilter filter, List files, boolean includeHiddenFiles)
  4. findByExt(File base, String ext)
  5. findByExtension(final File directory, final String extension)
  6. findExe(String exeName, String... path)
  7. findExecutable(File baseLocation)
  8. findExecutable(String executableName)
  9. findExecutableInDirectory(String executable, File directory)