java.io
Class File

java.lang.Object
  |
  +--java.io.File

public class File
extends Object

An instance of this class represents a file or directory.


Field Summary
static String pathSeparator
          System-dependent path-separator character, represented as a string.
static char pathSeparatorChar
          System-dependent path-separator character.
static String separator
          System-dependent separator character, represented as a string.
static char separatorChar
          System-dependent separator character.
 
Constructor Summary
File(File parent, String child)
          Creates a new File instance from a parent path and a child name string.
File(String pathname)
          Creates a new File instance from a pathname string.
File(String parent, String child)
          Creates a new File instance from a parent path and a child name string.
 
Method Summary
 boolean canRead()
          Tests whether the file can be read.
 boolean canWrite()
          Tests whether the file can be written to.
 boolean createNewFile()
          Creates a new file.
 boolean delete()
          Deletes the file.
 boolean exists()
          Tests if the file exists.
 String getName()
          Returns the name of the file or directory.
 String getPath()
          Returns the pathname of the file or directory.
 boolean isDirectory()
          Tests if the instance is a directory.
 boolean isFile()
          Tests if the instance is a file.
 long lastModified()
          Returns the last modified file time in milliseconds, starting at Jan/01/1970, 00:00:00 GMT.
 long length()
          Returns the absolute size of the file.
 String[] list()
          Returns an array of strings naming the files and directories in the directory represented by this instance.
 boolean mkdir()
          Creates a new directory.
 boolean mkdirs()
          Creates a new directory.
 String toString()
          Returns the pathname of the file or directory.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode
 

Field Detail

pathSeparator

public static String pathSeparator
System-dependent path-separator character, represented as a string.


pathSeparatorChar

public static char pathSeparatorChar
System-dependent path-separator character.


separator

public static String separator
System-dependent separator character, represented as a string.


separatorChar

public static char separatorChar
System-dependent separator character.

Constructor Detail

File

public File(File parent,
            String child)
Creates a new File instance from a parent path and a child name string.

Parameters:
parent - location for the new file or directory.
child - name of the new file or directory.

File

public File(String pathname)
Creates a new File instance from a pathname string.

Parameters:
pathname - name of the file or directory.

File

public File(String parent,
            String child)
Creates a new File instance from a parent path and a child name string.

Parameters:
parent - location for the new file or directory.
child - name of the new file or directory.
Method Detail

toString

public String toString()
Returns the pathname of the file or directory. The return vakue of a call to this method is equal to the return of a call to getPath().

Overrides:
toString in class Object
Returns:
Pathname of the file or directory.

canRead

public boolean canRead()
Tests whether the file can be read.

Returns:
true if the application can read this file, false otherwise.

canWrite

public boolean canWrite()
Tests whether the file can be written to.

Returns:
true if the application can write to this file, false otherwise.

createNewFile

public boolean createNewFile()
                      throws IOException
Creates a new file.

Returns:
true if the file was successfully created, false if the file already exists.
Throws:
IOException - if the file could not be created.

delete

public boolean delete()
Deletes the file.

Returns:
true if the file was successfully deleted, false otherwise.

exists

public boolean exists()
Tests if the file exists.

Returns:
true if the file exists, false otherwise.

getName

public String getName()
Returns the name of the file or directory.

Returns:
Name of the file or directory.

getPath

public String getPath()
Returns the pathname of the file or directory.

Returns:
Pathname of the file or directory.

isDirectory

public boolean isDirectory()
Tests if the instance is a directory.

Returns:
true if the instance is a directory, false otherwise.

isFile

public boolean isFile()
Tests if the instance is a file.

Returns:
true if the instance is a file, false otherwise.

lastModified

public long lastModified()
Returns the last modified file time in milliseconds, starting at Jan/01/1970, 00:00:00 GMT.

Returns:
time, or 0 if any error occurs.

length

public long length()
Returns the absolute size of the file.

Returns:
size or 0L in case the file does not exist.

list

public String[] list()
Returns an array of strings naming the files and directories in the directory represented by this instance.

Returns:
Array of strings naming the files and directories in the directory.

mkdir

public boolean mkdir()
Creates a new directory.

Returns:
true if the directory was successfully created, false otherwise.

mkdirs

public boolean mkdirs()
Creates a new directory.

Returns:
true if the directory tree was successfully created, false otherwise.