Here you can find the source of isRoot(File file)
public static boolean isRoot(File file)
//package com.java2s; /******************************************************************************* * Copyright (c) 2007, 2008 Tran Nam Quang. * 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:/* w w w.j av a 2 s. c om*/ * Tran Nam Quang - initial API and implementation *******************************************************************************/ import java.io.File; public class Main { /** * Returns whether the given folder is a root folder. On Windows, root * folders can be "C:", "D:", and so on. On Linux, the root folder is "/". * Returns false if the given file object does not represent a folder. */ public static boolean isRoot(File file) { File[] roots = File.listRoots(); for (File root : roots) if (file.equals(root)) return true; return false; } }