예제 #1
0
 /**
  * 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;
 }
예제 #2
0
  /**
   * It can be necessary to check if a path specified by the user is an absolute path (i.e
   * C:\Gfx\3d\Utils is absolute whereas ..\Jext is relative).
   *
   * @param path The path to check
   * @return <code>true</code> if <code>path</code> begins with a root name
   */
  public static boolean beginsWithRoot(String path) {
    if (path.length() == 0) return false;

    File file = new File(path);
    File[] roots = file.listRoots();
    for (int i = 0; i < roots.length; i++)
      if (path.regionMatches(true, 0, roots[i].getPath(), 0, roots[i].getPath().length()))
        return true;
    return false;
  }