Here you can find the source of relativePath(File parent, File child)
Parameter | Description |
---|---|
parent | a parameter |
child | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static final String relativePath(File parent, File child) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.IOException; public class Main { /**//ww w . ja v a 2s .co m * get relative path of <i>child</i> to <i>parent</i>.<br> * To be noticed, relative returned NOT start with "/" and file separator will be replaced by "/" * @param parent * @param child * @return * @throws IOException */ public static final String relativePath(File parent, File child) throws IOException { String parentPath = parent.getCanonicalPath(); String childPath = child.getCanonicalPath(); if (parentPath.equalsIgnoreCase(childPath)) { return ""; } else { return childPath.substring(parentPath.length() + 1).replace(File.separator, "/"); } } }