code: public static File getContextFile(Resource<?> r)
     {
        do
        {
           Object o = r.getUnderlyingResourceObject();
           if (o instanceof File)
           {
              return (File) r.getUnderlyingResourceObject();
           }
  
        }
        while ((r = r.getParent()) != null);
  
        return null;
     }
docs: A simple utility method to locate the outermost contextual File reference for the specified resource.
  
  @param r resource instance.
  @return outermost relevant file context.