File (String path, File defaultDir) { Set<String> macros = myMap.keySet(); String actualtPath = path; for (String each : macros) { actualtPath = actualtPath.replaceAll(each, myMap.get(each).getAbsolutePath()); } File file = new File(actualtPath); if (!file.isAbsolute()) { file = new File(defaultDir, actualtPath); } return file; }