Here you can find the source of resolvePathIfRelativeTo(File referenceFile, String partialPath)
Parameter | Description |
---|---|
referenceFile | a parameter |
partialPath | a parameter |
public static String resolvePathIfRelativeTo(File referenceFile, String partialPath)
//package com.java2s; /******************************************************************************* * Copyright (c) 2013, 2014 ETAS GmbH.//from w w w .jav a 2 s. c o m * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Dennis Eder (ETAS GmbH) - initial API and implementation and/or initial documentation *******************************************************************************/ import java.io.File; import java.nio.file.Paths; public class Main { /** * @param referenceFile * @param partialPath * @return If partialPath is not relative, then returns partialPath. * If partialPath is relative, then returns partialPath nested inside folder of referenceFile. */ public static String resolvePathIfRelativeTo(File referenceFile, String partialPath) { if (partialPath.startsWith("..") || partialPath.startsWith(".")) { String definitionOriginDir = referenceFile.getParentFile().getAbsolutePath(); partialPath = Paths.get(definitionOriginDir, partialPath).toAbsolutePath().toString(); } return partialPath; } }