fileio.java
来自「This is a resource based on j2me embedde」· Java 代码 · 共 573 行 · 第 1/2 页
JAVA
573 行
* @see java.lang.SecurityManager#checkRead(java.lang.String) * @since JDK1.0 */ public abstract boolean exists(); /** * Tests if the application can write to this file. * * @return <code>true</code> if the application is allowed to write to * a file whose name is specified by this object; * <code>false</code> otherwise. * @exception SecurityException if a security manager exists, its * <code>checkWrite</code> method is called with the pathname * of this <code>File</code> to see if the application is * allowed write access to the file. * @see java.io.File#getPath() * @see java.lang.SecurityManager#checkWrite(java.lang.String) * @since JDK1.0 */ public abstract boolean canWrite(); /** * Tests if the application can read from the specified file. * * @return <code>true</code> if the file specified by this object exists * and the application can read the file; * <code>false</code> otherwise. * @exception SecurityException if a security manager exists, its * <code>checkRead</code> method is called with the pathname * of this <code>File</code> to see if the application is * allowed read access to the file. * @see java.io.File#getPath() * @see java.lang.SecurityManager#checkRead(java.lang.String) * @since JDK1.0 */ public abstract boolean canRead(); /** * Tests if the file represented by this <code>File</code> * object is a "normal" file. * <p> * A file is "normal" if it is not a directory and, in * addition, satisfies other system-dependent criteria. Any * non-directory file created by a Java application is guaranteed to * be a normal file. * * @return <code>true</code> if the file specified by this object * exists and is a "normal" file; <code>false</code> otherwise. * @exception SecurityException If a security manager exists, its * <code>checkRead</code> method is called with the pathname * of this <code>File</code> to see if the application is * allowed read access to the file. * @see java.io.File#getPath() * @see java.lang.SecurityManager#checkRead(java.lang.String) * @since JDK1.0 */ public abstract boolean isFile(); /** * Tests if the file represented by this <code>File</code> * object is a directory. * * @return <code>true</code> if this <code>File</code> exists and is a * directory; <code>false</code> otherwise. * @exception SecurityException if a security manager exists, its * <code>checkRead</code> method is called with the pathname * of this <code>File</code> to see if the application is * allowed read access to the file. * @see java.io.File#getPath() * @see java.lang.SecurityManager#checkRead(java.lang.String) * @since JDK1.0 */ public abstract boolean isDirectory(); /** * Tests if the file represented by this <code>File</code> object is an * absolute pathname. The definition of an absolute pathname is system * dependent. For example, on UNIX, a pathname is absolute if its * first character is the separator character. On Windows platforms, * a pathname is absolute if its first character is an ASCII '\' or * '/', or if it begins with a letter followed by a colon. * * @return <code>true</code> if the pathname indicated by the * <code>File</code> object is an absolute pathname; * <code>false</code> otherwise. * @see java.io.File#getPath() * @see java.io.File#separator * @since JDK1.0 */ public abstract boolean isAbsolute(); /** * Returns the time that the file represented by this * <code>File</code> object was last modified. * <p> * The return value is system dependent and should only be used to * compare with other values returned by last modified. It should not * be interpreted as an absolute time. * * @return the time the file specified by this object was last modified, * or <code>0L</code> if the specified file does not exist. * @exception SecurityException if a security manager exists, its * <code>checkRead</code> method is called with the pathname * of this <code>File</code> to see if the application is * allowed read access to the file. * @see java.io.File#getPath() * @see java.lang.SecurityManager#checkRead(java.lang.String) * @since JDK1.0 */ public abstract long lastModified(); /** * Returns the length of the file represented by this * <code>File</code> object. * * @return the length, in bytes, of the file specified by this object, * or <code>0L</code> if the specified file does not exist. * @exception SecurityException if a security manager exists, its * <code>checkRead</code> method is called with the pathname * of this <code>File</code> to see if the application is * allowed read access to the file. * @see java.io.File#getPath() * @see java.lang.SecurityManager#checkRead(java.lang.String) * @since JDK1.0 */ public abstract long length(); /** * Creates a directory whose pathname is specified by this * <code>File</code> object. * * @return <code>true</code> if the directory could be created; * <code>false</code> otherwise. * @exception SecurityException if a security manager exists, its * <code>checkWrite</code> method is called with the pathname * of this <code>File</code> to see if the application is * allowed write access to the file. * @see java.io.File#getPath() * @see java.lang.SecurityManager#checkWrite(java.lang.String) * @since JDK1.0 */ public abstract boolean mkdir(); /** * Creates a directory whose pathname is specified by this * <code>File</code> object, including any necessary parent directories. * * @return <code>true</code> if the directory (or directories) could be * created; <code>false</code> otherwise. * @exception SecurityException if a security manager exists, its * <code>checkWrite</code> method is called with the pathname * of each of the directories that is to be created, before * any of the directories are created. * @see java.io.File#getPath() * @see java.lang.SecurityManager#checkWrite(java.lang.String) * @since JDK1.0 */ public boolean mkdirs() { if (exists()) { return false; } if (mkdir()) { return true; } String parent = getParent(); return (parent != null) && (FileIOFactory.newInstance(parent).mkdirs() && mkdir()); } /** * Renames the file specified by this <code>File</code> object to * have the pathname given by the <code>File</code> argument. * * @param dest the new filename. * @return <code>true</code> if the renaming succeeds; * <code>false</code> otherwise. * @exception SecurityException if a security manager exists, its * <code>checkWrite</code> method is called both with the * pathname of this file object and with the pathname of the * destination target object to see if the application is * allowed to write to both files. * @see java.io.File#getPath() * @see java.lang.SecurityManager#checkWrite(java.lang.String) * @since JDK1.0 abstract boolean renameTo(FileIO dest); */ /** * Returns a list of the files in the directory specified by this * <code>File</code> object. * * @return an array of file names in the specified directory. * This list does not include the current directory or the * parent directory ("<code>.</code>" and "<code>..</code>" * on Unix systems). * @exception SecurityException If a security manager exists, its * <code>checkRead</code> method is called with the pathname * of this <code>File</code> to see if the application is * allowed read access to the file. * @see java.io.File#getPath() * @see java.lang.SecurityManager#checkRead(java.lang.String) * @since JDK1.0 */ public abstract String[] list(); /** * Deletes the file specified by this object. If the target * file to be deleted is a directory, it must be empty for deletion * to succeed. * * @return <code>true</code> if the file is successfully deleted; * <code>false</code> otherwise. * @exception SecurityException if a security manager exists, its * <code>checkDelete</code> method is called with the * pathname of this <code>File</code> to see if the * application is allowed to delete the file. * @see java.io.File#getPath() * @see java.lang.SecurityManager#checkDelete(java.lang.String) * @since JDK1.0 */ abstract boolean delete(); /** * Computes a hashcode for the file. * * @return a hash code value for this <code>File</code> object. * @since JDK1.0 */ public int hashCode() { return path.hashCode() ^ 1234321; } /** * Compares this object against the specified object. * Returns <code>true</code> if and only if the argument is * not <code>null</code> and is a <code>File</code> object whose * pathname is equal to the pathname of this object. * * @param obj the object to compare with. * @return <code>true</code> if the objects are the same; * <code>false</code> otherwise. * @since JDK1.0 */ public boolean equals(Object obj) { if ((obj != null) && (obj instanceof FileIO)) { return path.equals(((FileIO) obj).path); } return false; } /** * Returns a string representation of this object. * * @return a string giving the pathname of this object. * @see java.io.File#getPath() * @since JDK1.0 */ public String toString() { return getPath(); } /** * WriteObject is called to save this filename. * The separator character is saved also so it can be replaced * in case the path is reconstituted on a different host type. */ private synchronized void writeObject(java.io.ObjectOutputStream s) throws IOException { s.defaultWriteObject(); s.writeChar(separatorChar); // Add the separator character } /** * readObject is called to restore this filename. * The original separator character is read. If it is different * than the separator character on this system. The old seperator * is replaced by the current separator. */ private synchronized void readObject(java.io.ObjectInputStream s) throws IOException, ClassNotFoundException { s.defaultReadObject(); char sep = s.readChar(); // read the previous seperator char if (sep != separatorChar) path = path.replace(sep, separatorChar); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?