Here you can find the source of getResourceFileRelativeToBase(final File baseDir, final String resourcePath)
public static File getResourceFileRelativeToBase(final File baseDir, final String resourcePath)
//package com.java2s; //License from project: Apache License import java.io.File; import java.net.URI; import java.net.URISyntaxException; public class Main { public static File getResourceFileRelativeToBase(final File baseDir, final String resourcePath) { final String baseDirUriString = baseDir != null ? baseDir.toURI().toString() : "file:/"; final boolean baseEndsWithSlash = baseDirUriString.endsWith("/"); final boolean resourcePathBeginsWithSlash = resourcePath.startsWith("/"); final String uriString; if (baseEndsWithSlash != resourcePathBeginsWithSlash) { uriString = baseDirUriString + resourcePath; } else if (baseEndsWithSlash) { uriString = baseDirUriString.substring(0, baseDirUriString.length() - 1) + resourcePath; } else {/*from www . j a v a2 s . c o m*/ uriString = baseDirUriString + "/" + resourcePath; } try { File f = new File(new URI(uriString)); return f; } catch (URISyntaxException e) { e.printStackTrace(); return null; } } }