Here you can find the source of relativePath(File root, File node)
Parameter | Description |
---|---|
root | the parent node |
node | the file node to compute the relative path for |
Parameter | Description |
---|---|
IOException | when an I/O error occurs during resolving the canonical path of the files |
public static String relativePath(File root, File node) throws IOException
//package com.java2s; /**/*ww w. j av a2s. com*/ * Copyright 2013 Thomas Rausch * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.io.File; import java.io.IOException; public class Main { /** * Computes the path name of a file node relative to a given root node. * <p/> * If the root is {@code /home/cdlflex/custom-ahy} and the given node is * {@code /home/cdlflex/custom-ahy/assembly/pom.xml}, the returned path name will be {@code assembly/pom.xml}. * * @param root the parent node * @param node the file node to compute the relative path for * @return the path of {@code node} relative to {@code root} * @throws IOException when an I/O error occurs during resolving the canonical path of the files */ public static String relativePath(File root, File node) throws IOException { String rootPath = root.getCanonicalPath(); String nodePath = node.getCanonicalPath(); return nodePath.substring(rootPath.length() + 1); } }