Here you can find the source of find(String name, File dir)
Parameter | Description |
---|---|
name | The filename to find. If the first character of the name is '*', then the match will be the first file that ends with the remaining string |
dir | The parent directory to start the search from |
public static File find(String name, File dir)
//package com.java2s; /*//from w w w . j a v a2s . c o m * Copyright 2008 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.io.File; public class Main { /** * Find a file in an extracted OAR directory * * @param name The filename to find. If the first character of the * name is '*', then the match will be the first file that ends with the * remaining string * @param dir The parent directory to start the search from * * @return The file, or null if not found */ public static File find(String name, File dir) { File found = null; File[] files = dir.listFiles(); if (files != null) { for (File file : files) { if (file.isDirectory()) { found = find(name, file); if (found != null) break; } if (name.startsWith("*")) { if (file.getName().endsWith(name)) { found = file; break; } } else { if (file.getName().equals(name)) { found = file; break; } } } } return found; } }