Java tutorial
//package com.java2s; import java.io.File; import java.io.FileFilter; public class Main { /** * Resource directory name that we are looking for. */ protected static final String RESOURCE_DIR_NAME = "res"; /** * Raw directory name that we are looking for. */ protected static final String RAW_DIR_NAME = "raw"; /** * Look for the resource-directory in the current directory or the directories above. Then look for the * raw-directory underneath the resource-directory. */ protected static File findRawDir(File dir) { for (int i = 0; dir != null && i < 20; i++) { File rawDir = findResRawDir(dir); if (rawDir != null) { return rawDir; } dir = dir.getParentFile(); } return null; } /** * Look for the resource directory with raw beneath it. */ private static File findResRawDir(File dir) { for (File file : dir.listFiles()) { if (file.getName().equals(RESOURCE_DIR_NAME) && file.isDirectory()) { File[] rawFiles = file.listFiles(new FileFilter() { public boolean accept(File file) { return file.getName().equals(RAW_DIR_NAME) && file.isDirectory(); } }); if (rawFiles.length == 1) { return rawFiles[0]; } } } return null; } }