get File System Root For Path - Android java.io

Android examples for java.io:Directory

Description

get File System Root For Path

Demo Code

import java.io.File;

public class Main {

   static File getFSRootForPath(File path) {
    while (path != null && path.isDirectory()) {
      long fsSize = path.getTotalSpace();
      File parent = path.getParentFile();
      if (parent == null || parent.getTotalSpace() != fsSize)
        return path;
      path = parent;//from   w  ww  . jav  a2  s.  c o m
    }
    return path;
  }

}

Related Tutorials