Java Utililty Methods Root Directory Get

List of utility methods to do Root Directory Get

Description

The list of methods to do Root Directory Get are organized into topic(s).

Method

FilegetRoot(final File workingDirectory)
Gets the root (or project) directory of a project.
File ref = workingDirectory;
while (ref.getParentFile() != null && new File(ref.getParentFile(), POM_FILE).exists()) {
    ref = ref.getParentFile();
return ref;
StringgetRoot(final String path)
It can be necessary to determine which is the root of a path.
final File roots[] = listRoots(new File(path));
for (int i = 0; i < roots.length; i++) {
    if (path.startsWith(roots[i].getPath())) {
        return roots[i].getPath();
return path;
StringgetRoot(String path)
It can be necessary to determine which is the root of a 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;
StringgetRootDir()
get Root Dir
File currentDir = new File(".");
return currentDir.getCanonicalPath();
FilegetRootDir()
get Root Dir
return getOmHome().getParentFile().getParentFile();
FilegetRootDir()
get Root Dir
String rootDir = System.getProperty("user.home", ".");
File rootFile = new File(rootDir, ".autotest");
if (!rootFile.isDirectory()) {
    rootFile.mkdirs();
return rootFile;
FilegetRootDir()
get Root Dir
File rootDir = new File(System.getProperty("user.dir"));
File parentPom = new File(rootDir.getParent(), "pom.xml");
while (parentPom.exists()) {
    rootDir = rootDir.getParentFile();
    parentPom = new File(rootDir.getParent(), "pom.xml");
return rootDir;
StringgetRootDir()
Get root directory for current work directory
String userDir = System.getProperty(USER_DIR);
String rootDir = userDir.substring(0, userDir.indexOf(File.separator) + 1);
if (!rootDir.endsWith(File.separator)) {
    rootDir += File.separator;
return rootDir;
FilegetRootDir()
get Root Dir
if (rootDir == null) {
    rootDir = new File(System.getProperty("java.io.tmpdir") + File.separator + ".dorado.tmp");
    if (!rootDir.exists()) {
        if (!rootDir.mkdirs()) {
            throw new IOException("Make directory \"" + rootDir.getAbsolutePath() + "\" failed.");
    } else if (!rootDir.isDirectory()) {
        throw new IOException("\"" + rootDir.getAbsolutePath() + "\" is not a directory.");
...
FilegetRootDir()
get Root Dir
String os = System.getProperty("os.name").toUpperCase();
if (os.contains("WIN")) {
    return new File(System.getenv("APPDATA"), "routeKIT");
} else if (os.contains("MAC")) {
    return new File(new File(new File(System.getProperty("user.home"), "Library"), "Application Support"),
            "routeKIT");
} else if (os.matches(".*N[IU]X.*")) {
    return new File(new File(System.getProperty("user.home"), ".config"), "routeKIT");
...