Here you can find the source of getRoot(String path)
Parameter | Description |
---|---|
path | The path used to get a root |
public static String getRoot(String path)
//package com.java2s; /*//w w w. j av a2s . c o m * Copyright (c) 1998 - 2005 Versant Corporation * 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: * Versant Corporation - initial API and implementation */ import java.io.File; public class Main { /** * It can be necessary to determine which is the root of a path. * For example, the root of D:\Projects\Java is D:\. * @param path The path used to get a root * @return The root which contais the specified path */ public static String getRoot(String path) { File file = new File(path); File[] roots = file.listRoots(); for (int i = 0; i < roots.length; i++) if (path.startsWith(roots[i].getPath())) return roots[i].getPath(); return path; } }