Here you can find the source of removeDriveLetter(Path path)
Parameter | Description |
---|---|
path | path to remove root from |
static public Path removeDriveLetter(Path path)
//package com.java2s; /* The MIT License (MIT) * Copyright (c) 2014 Nicholas Wright/*from ww w . ja v a 2 s . co m*/ * http://opensource.org/licenses/MIT */ import java.nio.file.Path; import java.nio.file.Paths; public class Main { /** * Remove the root component from the path, returning a relative path. If the path is already relative, it will not be changed. C:\temp\ * becomes \temp\ * * @param path * path to remove root from * @return a relative path */ static public Path removeDriveLetter(Path path) { if (path == null) { return null; } if (path.isAbsolute()) { return Paths.get(path.getRoot().relativize(path).toString()); } else { return path; } } static public String removeDriveLetter(String path) { if (path == null) { return null; } Path relPath = removeDriveLetter(Paths.get(path)); String filename = relPath.getFileName().toString(); if (filename.contains(".")) { return relPath.toString(); } else { return relPath.toString() + "\\"; } } }