⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 file.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
  }  /**   * This method returns a <code>File</code> object representing the   * absolute path of this object.   *   * @return A <code>File</code> with the absolute path of the object.   *   * @since 1.2   */  public File getAbsoluteFile()  {    return new File(getAbsolutePath());  }  /**   * This method returns a canonical representation of the pathname of   * this file.  The actual form of the canonical representation is   * different.  On the GNU system, the canonical form differs from the   * absolute form in that all relative file references to "." and ".."   * are resolved and removed.   * <p>   * Note that this method, unlike the other methods which return path   * names, can throw an IOException.  This is because native method    * might be required in order to resolve the canonical path   *   * @exception IOException If an error occurs   */  public String getCanonicalPath() throws IOException  {    // On Windows, getAbsolutePath might end up calling us, so we    // have to special case that call to avoid infinite recursion.    if (separatorChar == '\\' && path.length() == 2 &&	((path.charAt(0) >= 'a' && path.charAt(0) <= 'z') ||	 (path.charAt(0) >= 'A' && path.charAt(0) <= 'Z')) &&	path.charAt(1) == ':')    {	return VMFile.toCanonicalForm(path);    }    // Call getAbsolutePath first to make sure that we do the    // current directory handling, because the native code    // may have a different idea of the current directory.    return VMFile.toCanonicalForm(getAbsolutePath());  }  /**   * This method returns a <code>File</code> object representing the   * canonical path of this object.   *   * @return A <code>File</code> instance representing the canonical path of   * this object.   *   * @exception IOException If an error occurs.   *   * @since 1.2   */  public File getCanonicalFile() throws IOException  {    return new File(getCanonicalPath());  }  /**   * This method returns the name of the file.  This is everything in the   * complete path of the file after the last instance of the separator   * string.   *   * @return The file name   */  public String getName()  {  	return VMFile.getName(path);  }  /**   * This method returns a <code>String</code> the represents this file's   * parent.  <code>null</code> is returned if the file has no parent.  The   * parent is determined via a simple operation which removes the   *   * @return The parent directory of this file   */  public String getParent()  {    String prefix = null;    int nameSeqIndex = 0;        if (path.equals(""))      return null;    // The "prefix", if present, is the leading "/" on UNIX and     // either the drive specifier (e.g. "C:") or the leading "\\"    // of a UNC network path on Windows.    if (separatorChar == '/' && path.charAt (0) == '/')      {        prefix = "/";        nameSeqIndex = 1;      }    else if (separatorChar == '\\' && path.length() > 1)      {        if ((path.charAt (0) == '\\' && path.charAt (1) == '\\')            || (((path.charAt (0) >= 'a' && path.charAt (0) <= 'z')                 || (path.charAt (0) >= 'A' && path.charAt (0) <= 'Z'))                && path.charAt (1) == ':'))          {            prefix = path.substring (0, 2);            nameSeqIndex = 2;          }      }    // According to the JDK docs, the returned parent path is the     // portion of the name sequence before the last separator    // character, if found, prefixed by the prefix, otherwise null.    if (nameSeqIndex < path.length())      {        String nameSeq = path.substring (nameSeqIndex, path.length());        int last = nameSeq.lastIndexOf (separatorChar);        if (last == -1)          return prefix;        else if (last == (nameSeq.length() - 1))          // Note: The path would not have a trailing separator          // except for cases like "C:\" on Windows (see           // normalizePath( )), where Sun's JRE 1.4 returns null.          return null;        else if (last == 0)          last++;        if (prefix != null)          return prefix + nameSeq.substring (0, last);        else          return nameSeq.substring (0, last);      }    else      // Sun's JRE 1.4 returns null if the prefix is the only       // component of the path - so "/" gives null on UNIX and       // "C:", "\\", etc. return null on Windows.      return null;  }  /**   * This method returns a <code>File</code> object representing the parent   * file of this one.   *   * @return a <code>File</code> for the parent of this object.     * <code>null</code>   * will be returned if this object does not have a parent.   *   * @since 1.2   */  public File getParentFile()  {    String parent = getParent();    return parent != null ? new File(parent) : null;  }  /**   * Returns the path name that represents this file.  May be a relative   * or an absolute path name   *   * @return The pathname of this file   */  public String getPath()  {    return path;  }  /**   * This method returns a hash code representing this file.  It is the   * hash code of the path of this file (as returned by <code>getPath()</code>)   * exclusived or-ed with the value 1234321.   *   * @return The hash code for this object   */  public int hashCode()  {    if (VMFile.IS_CASE_SENSITIVE)      return path.hashCode() ^ 1234321;    else      return path.toLowerCase().hashCode() ^ 1234321;  }  /**   * This method returns true if this object represents an absolute file   * path and false if it does not.  The definition of an absolute path varies   * by system.  As an example, on GNU systems, a path is absolute if it starts   * with a "/".   *   * @return <code>true</code> if this object represents an absolute    * file name, <code>false</code> otherwise.   */  public boolean isAbsolute()  {    if (separatorChar == '\\')	return path.startsWith(dupSeparator) || 	    (path.length() > 2 && 	     ((path.charAt(0) >= 'a' && path.charAt(0) <= 'z') ||	      (path.charAt(0) >= 'A' && path.charAt(0) <= 'Z')) &&	     path.charAt(1) == ':' &&	     path.charAt(2) == '\\');    else	return path.startsWith(separator);  }  /**   * This method tests whether or not the file represented by this object   * is a directory.  In order for this method to return <code>true</code>,   * the file represented by this object must exist and be a directory.   *    * @return <code>true</code> if this file is a directory, <code>false</code>   * otherwise   *   * @exception SecurityException If reading of the file is not permitted   */  public boolean isDirectory()  {    checkRead();    return VMFile.isDirectory(path);   }  /**   * This method tests whether or not the file represented by this object   * is a "plain" file.  A file is a plain file if and only if it 1) Exists,   * 2) Is not a directory or other type of special file.   *   * @return <code>true</code> if this is a plain file, <code>false</code>    * otherwise   *   * @exception SecurityException If reading of the file is not permitted   */  public boolean isFile()  {    checkRead();    return VMFile.isFile(path);  }  /**   * This method tests whether or not this file represents a "hidden" file.   * On GNU systems, a file is hidden if its name begins with a "."   * character.  Files with these names are traditionally not shown with   * directory listing tools.   *   * @return <code>true</code> if the file is hidden, <code>false</code>   * otherwise.   *   * @since 1.2   */  public boolean isHidden()  {    return VMFile.isHidden(path);  }  /**   * This method returns the last modification time of this file.  The   * time value returned is an abstract value that should not be interpreted   * as a specified time value.  It is only useful for comparing to other   * such time values returned on the same system.  In that case, the larger   * value indicates a more recent modification time.    * <p>   * If the file does not exist, then a value of 0 is returned.   *   * @return The last modification time of the file   *   * @exception SecurityException If reading of the file is not permitted   */  public long lastModified()  {    checkRead();    return VMFile.lastModified(path);  }  /**   * This method returns the length of the file represented by this object,   * or 0 if the specified file does not exist.   *   * @return The length of the file   *   * @exception SecurityException If reading of the file is not permitted   */  public long length()  {    checkRead();    return VMFile.length(path);  }  /**   * This method returns a array of <code>String</code>'s representing the   * list of files is then directory represented by this object.  If this   * object represents a non-directory file or a non-existent file, then   * <code>null</code> is returned.  The list of files will not contain   * any names such as "." or ".." which indicate the current or parent   * directory.  Also, the names are not guaranteed to be sorted.   * <p>   * In this form of the <code>list()</code> method, a filter is specified   * that allows the caller to control which files are returned in the   * list.  The <code>FilenameFilter</code> specified is called for each   * file returned to determine whether or not that file should be included   * in the list.   * <p>   * A <code>SecurityManager</code> check is made prior to reading the   * directory.  If read access to the directory is denied, an exception   * will be thrown.   *   * @param filter An object which will identify files to exclude from    * the directory listing.   *   * @return An array of files in the directory, or <code>null</code>    * if this object does not represent a valid directory.   *    * @exception SecurityException If read access is not allowed to the    * directory by the <code>SecurityManager</code>   */  public String[] list(FilenameFilter filter)  {    checkRead();    if (!exists() || !isDirectory())      return null;        // Get the list of files    String files[] = VMFile.list(path);        // Check if an error occured in listInternal().    if (files == null)      return null;    if (filter == null)      return files;        // Apply the filter    int count = 0;    for (int i = 0; i < files.length; i++)      {        if (filter.accept(this, files[i]))  	  ++count;        else  	  files[i] = null;      }    String[] retfiles = new String[count];    count = 0;    for (int i = 0; i < files.length; i++)      if (files[i] != null)        retfiles[count++] = files[i];    return retfiles;  }  /**   * This method returns a array of <code>String</code>'s representing the   * list of files is then directory represented by this object.  If this   * object represents a non-directory file or a non-existent file, then   * <code>null</code> is returned.  The list of files will not contain   * any names such as "." or ".." which indicate the current or parent   * directory.  Also, the names are not guaranteed to be sorted.   * <p>   * A <code>SecurityManager</code> check is made prior to reading the   * directory.  If read access to the directory is denied, an exception   * will be thrown.   *   * @return An array of files in the directory, or <code>null</code> if    * this object does not represent a valid directory.   *    * @exception SecurityException If read access is not allowed to the    * directory by the <code>SecurityManager</code>   */  public String[] list()  {    return list(null);  }  /**   * This method returns an array of <code>File</code> objects representing   * all the files in the directory represented by this object. If this   * object does not represent a directory, <code>null</code> is returned.   * Each of the returned <code>File</code> object is constructed with this   * object as its parent.   * <p>   * A <code>SecurityManager</code> check is made prior to reading the   * directory.  If read access to the directory is denied, an exception   * will be thrown.   *   * @return An array of <code>File</code> objects for this directory.   *   * @exception SecurityException If the <code>SecurityManager</code> denies   * access to this directory.   *   * @since 1.2   */  public File[] listFiles()  {    return listFiles((FilenameFilter) null);  }    /**   * This method returns an array of <code>File</code> objects representing   * all the files in the directory represented by this object. If this   * object does not represent a directory, <code>null</code> is returned.   * Each of the returned <code>File</code> object is constructed with this   * object as its parent.   * <p>    * In this form of the <code>listFiles()</code> method, a filter is specified   * that allows the caller to control which files are returned in the   * list.  The <code>FilenameFilter</code> specified is called for each   * file returned to determine whether or not that file should be included   * in the list.   * <p>   * A <code>SecurityManager</code> check is made prior to reading the   * directory.  If read access to the directory is denied, an exception   * will be thrown.   *   * @return An array of <code>File</code> objects for this directory.   *   * @exception SecurityException If the <code>SecurityManager</code> denies   * access to this directory.   *   * @since 1.2   */  public File[] listFiles(FilenameFilter filter)  {    String[] filelist = list(filter);        if (filelist == null)      return null;    File[] fobjlist = new File [filelist.length];    for (int i = 0; i < filelist.length; i++)      fobjlist [i] = new File(this, filelist [i]);    return fobjlist;  }  /**   * This method returns an array of <code>File</code> objects representing   * all the files in the directory represented by this object. If this   * object does not represent a directory, <code>null</code> is returned.   * Each of the returned <code>File</code> object is constructed with this   * object as its parent.   * <p>    * In this form of the <code>listFiles()</code> method, a filter is specified   * that allows the caller to control which files are returned in the   * list.  The <code>FileFilter</code> specified is called for each   * file returned to determine whether or not that file should be included   * in the list.   * <p>   * A <code>SecurityManager</code> check is made prior to reading the   * directory.  If read access to the directory is denied, an exception   * will be thrown.   *   * @return An array of <code>File</code> objects for this directory.   *   * @exception SecurityException If the <code>SecurityManager</code> denies   * access to this directory.   *   * @since 1.2   */  public File[] listFiles(FileFilter filter)  {    File[] fobjlist = listFiles((FilenameFilter) null);    if (fobjlist == null)      return null;    if (filter == null)      return fobjlist;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -