Here you can find the source of relativizePath(String basePath, File toRelativize)
Parameter | Description |
---|---|
basePath | The base directory path to remove from the file path. |
toRelativize | The file to be made relative. |
@Deprecated public static String relativizePath(String basePath, File toRelativize)
//package com.java2s; /*//from w w w. ja va 2 s .c o m * Copyright 2012 Johns Hopkins University * * 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.nio.file.FileSystems; import java.nio.file.Path; public class Main { /** * This method has been deprecated use the Java Path relativize method instead. * Strips the base directory out of a file path to make a relative file path. If the file doesn't contain the base path the original path is returned. * @param basePath The base directory path to remove from the file path. * @param toRelativize The file to be made relative. * @return The relative file path created by removing the base directory. Returns null if the file to relative is null. */ @Deprecated public static String relativizePath(String basePath, File toRelativize) { if (toRelativize == null) { return null; } if (basePath == null || !toRelativize.getPath().startsWith(basePath)) { return toRelativize.getPath(); } Path path = FileSystems.getDefault().getPath(basePath); Path relativePath = path.relativize(toRelativize.toPath()); return relativePath.toString(); } }