Here you can find the source of toFileWithAbsolutePath(String relativePath)
Parameter | Description |
---|---|
relativePath | the relative path for which we want the corresponding file. |
public static File toFileWithAbsolutePath(String relativePath)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.nio.file.FileSystems; import java.nio.file.Path; public class Main { /**//from w w w . j ava 2 s .c o m * Upstream, based on branch 'master' of git@github.com:adaussy/EMFCompareGitPGM.git Returns, from a * relative path, the corresponding file with an absolute path. This absolute path is computed against * 'user.dir' system property. * * @param relativePath * the relative path for which we want the corresponding file. * @return the corresponding file with an absolute path. */ public static File toFileWithAbsolutePath(String relativePath) { return toFileWithAbsolutePath(System.getProperty("user.dir"), relativePath); //$NON-NLS-1$ } /** * Returns, from a relative path, the corresponding file with an absolute path. This absolute path is * computed against the given base path. * * @param relativePath * the relative path for which we want the corresponding file. * @return the corresponding file with an absolute path. */ public static File toFileWithAbsolutePath(String basePath, String relativePath) { File file = new File(relativePath); if (!file.isAbsolute()) { Path base = FileSystems.getDefault().getPath(basePath); Path resolvedPath = base.resolve(file.toPath()); Path absolutePath = resolvedPath.normalize(); file = absolutePath.toFile(); } return file; } }