Java tutorial
//package com.java2s; //License from project: Apache License import java.io.File; import java.util.Arrays; public class Main { /***********************************************************************/ public static String locateFile(String fileLocation, String backupPaths[]) throws Exception { String[] newArray = new String[backupPaths.length + 1]; System.arraycopy(backupPaths, 0, newArray, 1, backupPaths.length); newArray[0] = "."; backupPaths = newArray; for (int i = 0; i < backupPaths.length; i++) { String tfileLocation = backupPaths[i] + File.separator + fileLocation; File file = new File(tfileLocation); if (file.exists()) { return file.getAbsolutePath(); } } throw new Error(String.format("Couldn't find '%s' from locations %s with current directory '%s'", fileLocation, Arrays.asList(backupPaths), new File(".").getAbsolutePath())); } }