Home | Blog | Java | Jokes | Poems | Musings | Site Map | Kudos | Downloads | Useful Sites | Interesting | System Setup | Contact

Home Page

AKGBackup - The backup program



Section 11 : The java.io Package




Write code that uses objects of the file class to navigate a file system.





This class extends Object, implements Comparable, Serializable. The current user directory is named by the system property user.dir, and is usually the directory in which the JVM was invoked. File is an abstract representation of file and directory path names. Instances of this class are immutable.



  • static final String pathSeparator

The system dependent path separator character, represented as a string for convenience. This string contains a single character, namely pathSeparatorChar.

  • static final char pathSeparatorChar

System dependent.

  • static final String separator

The system dependent default name separator character, represented as a string for convenience. This string contains a single character, namely separatorChar.

  • static final char separatorChar




  • File (File parent, String child)

If parent is null then the new file instance is created as if by invoking File(String pathname). Otherwise, the parent abstract pathname is taken to denote a directory, and child is taken either as a directory or a file.

Throws NullPointerException if child is null.

  • File (String pathname)

Throws NullPointerException if pathname is null.

  • File (String parent, String child)

Same as first constructor.



  • boolean canRead()

  • boolean canWrite ()

  • boolean exists ()

  • boolean isFile ()

  • boolean isDirectory()

  • int compareTo(File pathname)

  • int compareTo(Object obj)

if the other object is an abstract pathname, then this method behaves as the previous method, otherwise ClassCastException is thrown.

  • boolean createNewFile()

Atomically creates a new, empty file named by this abstract pathname if and only if a file with this name does not exist yet. Returns false if the named file already exists.

Throws IOException.

  • static File createTempFile(String prefix, String suffix)

Throws IOException.

  • static File createTempFile(String prefix, String suffix, File directory)

Throws IOException.

  • boolean delete()

deletes this file or directory. If it is a directory, then the directory must be empty in order to be deleted.

  • void deleteOnExit()

Requests that file be deleted when JVM terminates. Once the request has been made, it is not possible to cancel the request.

  • File getAbsoluteFile()

  • String getAbsolutePath()

  • File getCanonicalFile()

  • String getCanonicalPath()

  • String getName()

  • String getParent()

Returns null if this pathname does not name a parent directory.

  • File getParentFile ()

  • String getPath ()

Converts this abstract pathname to a pathname string.

  • boolean isAbsolute ()

  • boolean isHidden ()

  • long lastModified ()

Returns zero if the file does not exist or if an I/O error occurs.

  • long length ()

  • String [] list ()

If this file object does not denote a directory then this and the following method return null. Names denoting the directory itself and the directory’s parent directory are not included in the result. Each string is a file name rather than a complete path.

  • String [] list (FileNameFilter filter)

  • File [] listFiles ()

If this file object does not denote a directory then this method returns null. If this pathname is absolute then each resulting pathname is absolute; if this pathname is relative then each resulting pathname will be relative to the same directory.

  • static file [] listRoots ()

  • boolean mkdir ()

  • boolean mkdirs()

Creates the directory named by this abstract pathname, including any necessary but non existent parent directories. If this operation fails, it may have succeeded in creating some of the necessary parent directories. Returns true only if the directory, along with all necessary parent directories was created; false otherwise.

  • boolean renameTo (File destination)

Throws SecurityException. Throws NullPointerException if destination is null.

  • boolean setLastModified (long n)

throws IllegalArgumentException if n is negative.

  • boolean setReadOnly ()

  • URL toURL ()

Converts this object into a file:URL. Throws MalformedException if the path cannot be passed as a URL.




section11-1 | section11-2 | section11-3 | section11-4 | section11-5 | section11-6


Sections : 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11







Home | Blog | Java | Jokes | Poems | Musings | Site Map | Kudos | Downloads | Useful Sites | Interesting | System Setup | Contact  


 Number of Pages viewed on this site since January' 2003 : Hit Counter eXTReMe Tracker

For any queries, comments or suggestions, write to me .

This site never compromises your privacy, please read this site's privacy policy.