Example #1
0
 /**
  * Method to build an absolute path
  *
  * @param dir the root dir
  * @param name the name of the new directory
  * @return if name is an absolute directory, returns name, else returns dir+name
  */
 public static String getDir(String dir, String name) {
   if (!dir.endsWith(File.separator)) dir = dir + File.separator;
   File mv = new File(name);
   String new_dir = null;
   if (!mv.isAbsolute()) {
     new_dir = dir + name;
   } else new_dir = name;
   return new_dir;
 }
Example #2
0
  /** Create a FILE object to read from the specified filename. */
  public static FILE openFile(String filename) {
    try {
      FILE f = null;
      File file = new File(filename);

      if (file.isAbsolute()) {
        f = open(file);
      } else {
        if (documentBase != null) {
          String docBase = documentBase.toString();
          if (docBase.startsWith("file:/")) {
            docBase = docBase.substring(6);
            file = new File(docBase, filename);

            f = open(file);
          }
        }

        if (f == null && codeBase != null) {
          String cBase = codeBase.toString();
          if (cBase.startsWith("file:/")) {
            cBase = cBase.substring(6);
            file = new File(cBase, filename);

            f = open(file);
          }
        }

        if (f == null) {
          file = new File(filename);

          f = open(file);
        }
      }

      return f;
    } catch (Exception e) {
      setException(e);

      if (debug) {
        System.out.println("openFile: " + e);
      }
      return null;
    }
  }