Here you can find the source of getRelativeFilePath(String filePath, String relativePathPrefix)
Parameter | Description |
---|---|
filePath | a parameter |
relativePathPrefix | a parameter |
public static String getRelativeFilePath(String filePath, String relativePathPrefix)
//package com.java2s; import java.io.File; public class Main { /**// w w w . ja va 2 s . co m * Get relative path that follows {@code relativePathPrefix}. If {@code relativePathPrefix} is * not found in {@code filePath}, then filePath is returned. * * @param filePath * @param relativePathPrefix * @return relative path if relativePathPrefix is found; otherwise, absolutePath. */ public static String getRelativeFilePath(String filePath, String relativePathPrefix) { int prefixIndex = filePath.indexOf(relativePathPrefix); if (prefixIndex == -1) return filePath; int relativePathStartIndex = prefixIndex + relativePathPrefix.length() + 1; return filePath.substring(relativePathStartIndex); } /** * Returns a relative path to the input file. This method assumes a certain directory structure * and returns a relative path starting at the {@code relativePathPrefix} directory. * * @param file * @return */ public static String getRelativeFilePath(File file, String relativePathPrefix) { if (relativePathPrefix == null) return file.toURI().toString(); return getRelativeFilePath(file.getAbsolutePath(), relativePathPrefix); } }