code: public static String[] getCanonicalPathElements (File file)
          throws IOException
      {
          file = file.getCanonicalFile();
  
          // If we were a file, get its parent
          if (!file.isDirectory()) {
              file = file.getParentFile();
          }
  
          return file.getPath().split(File.separator);
      }
docs: Gets the individual path elements building up the canonical path to the given file.