示例#1
0
 /**
  * Returns the absolute path for the given file. It tries to get the canonical file path. If it
  * fails it returns the string representation.
  *
  * @param f File to get the path
  * @return the absolute path for the given file.
  */
 static String getPath(File f) {
   String path = null;
   if (f != null) {
     try {
       /*
        * Do a best effort to avoid having a relative representation (for
        * instance to avoid having ../../../).
        */
       f = f.getCanonicalFile();
     } catch (IOException ioe) {
       /*
        * This is a best effort to get the best possible representation of the
        * file: reporting the error is not necessary.
        */
     }
     path = f.toString();
   }
   return path;
 }