Java is Root File isRoot(File file)

Here you can find the source of isRoot(File file)

Description

Returns whether the given folder is a root folder.

License

Open Source License

Declaration

public static boolean isRoot(File file) 

Method Source Code

//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;
    }
}

Related

  1. isRoot()
  2. isRootDir(File dir)
  3. isRootDir(String dir)
  4. isRootOfSeqWare(File workingDirectory)
  5. isRootPath(File file)