Java tutorial
//package com.java2s; //License from project: Open Source License import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; public class Main { public static InputStream openCacheFileForInput(File root, String... path) throws FileNotFoundException { return new BufferedInputStream(new FileInputStream(openPath(false, root, path))); } public static File openPath(boolean createPath, File root, String... path) { File f = root; for (int i = 0; i < path.length; i++) { String component = path[i]; if (i == path.length - 1) { // This is the file component so now we create parent directories if (createPath) { f.mkdirs(); } } f = new File(f, component); } return f; } }