code: public static String getPackageName(String filePath) {
          char sep = File.separatorChar;
          int n = filePath.lastIndexOf(sep);
          if (n == -1  && sep != '/') {
              // Try with linux separator if the system separator is not found.
              sep = '/';
              n = filePath.lastIndexOf(sep);
          }
  
          return n < 0 ? "." : filePath.substring(0, n).replace(sep, '.');
      }
docs: Computes the package name from the given file path.
  The path is a relative path from the class/source root.
  For example {@code foo/bar/Baz.class} generates the {@code foo.bar} package.
  
  @param filePath the file's path
  @return the package name