Ja.NET Standard Edition 5.0

Documentation API Specification

Contents

File Class Reference

Inherits java::io::Serializable.

Inherited by PlatformFile.

List of all members.


Detailed Description

File is a class which represents a file name or directory.

The file may be absolute relative to the root directory of the file system or relative to the current directory in which the program is running.

This class provides methods for querying/changing information about the file and also directory listing capabilities if the File represents a directory.

When manipulating file paths, the static fields of this class may be used to determine the platform specific separators.

See also:
java.io.Serializable

java.lang.Comparable


Public Member Functions

 File (File dir, String name)
 Constructs a new File using the specified directory and name.
 File (String path)
 Constructs a new File using the specified path.
 File (String dirPath, String name)
 Constructs a new File using the specified directory and name placing a path separator between the two.
 File (URI uri)
 Constructs a new File using the path of the specified URI.
boolean canRead ()
 Answers a boolean indicating whether or not the current context is allowed to read this File.
boolean canWrite ()
 Answers a boolean indicating whether or not the current context is allowed to write to this File.
int compareTo (File another)
 Answers the relative sort ordering of paths for the receiver and given argument.
boolean delete ()
 Deletes the file specified by this File.
void deleteOnExit ()
 When the virtual machine terminates, any abstract files which have been sent deleteOnExit() will be deleted.
boolean equals (Object obj)
 Compares the argument obj to the receiver, and answers true if they represent the same object using a path specific comparison.
boolean exists ()
 Answers a boolean indicating whether or not this File can be found on the underlying file system.
String getAbsolutePath ()
 Answers the absolute file path of this File.
File getAbsoluteFile ()
 Answers a new File constructed using the absolute file path of this File.
String getCanonicalPath () throws IOException
 Answers the absolute file path of this File with all references resolved.
File getCanonicalFile () throws IOException
 Answers a new File created using the canonical file path of this File.
String getName ()
 Answers the filename (not directory) of this File.
String getParent ()
 Answers the pathname of the parent of this File.
File getParentFile ()
 Answers a new File made from the pathname of the parent of this File.
String getPath ()
 Answers the file path of this File.
int hashCode ()
 Answers an integer hash code for the receiver.
boolean isAbsolute ()
 Answers if this File is an absolute pathname.
boolean isDirectory ()
 Answers if this File represents a directory on the underlying file system.
boolean isFile ()
 Answers if this File represents a file on the underlying file system.
boolean isHidden ()
 Returns whether or not this file is a hidden file as defined by the operating system.
long lastModified ()
 Answers the time this File was last modified.
boolean setLastModified (long time)
 Sets the time this File was last modified.
boolean setReadOnly ()
 Marks this file or directory to be read-only as defined by the operating system.
long length ()
 Answers the length of this File in bytes.
String[] list ()
 Answers an array of Strings representing the file names in the directory represented by this File.
File[] listFiles ()
 Answers an array of Files representing the file names in the directory represented by this File.
File[] listFiles (FilenameFilter filter)
 Answers an array of Files representing the file names in the directory represented by this File that match a specific filter.
File[] listFiles (FileFilter filter)
 Answers an array of Files representing the file names in the directory represented by this File that match a specific filter.
String[] list (FilenameFilter filter)
 Answers an array of Strings representing the file names in the directory represented by this File that match a specific filter.
boolean mkdir ()
 Creates the directory named by the trailing filename of this File.
boolean mkdirs ()
 Create all the directories needed for this File.
boolean createNewFile () throws IOException
 Creates the file specified by this File.
boolean renameTo (File dest)
 Renames this File to the name represented by the File dest.
String toString ()
 Answers a string containing a concise, human-readable description of the receiver.
URI toURI ()
 Answers a file URI for this File.
URL toURL () throws java.net.MalformedURLException
 Answers a file URL for this File.

Static Public Member Functions

static File[] listRoots ()
 Lists the filesystem roots.
static File createTempFile (String prefix, String suffix) throws IOException
 Creates an empty temporary file using the given prefix and suffix as part of the file name.
static File createTempFile (String prefix, String suffix, File directory) throws IOException
 Creates an empty temporary file in the given directory using the given prefix and suffix as part of the file name.

Static Public Attributes

static final char separatorChar
 System dependent file separator character.
static final String separator
 System dependent file separator String.
static final char pathSeparatorChar
 System dependent path separator character.
static final String pathSeparator
 System dependent path separator String.

Static Package Functions

 [static initializer]

Private Member Functions

void checkURI (URI uri)
boolean isHidden0 (String path)
long lastModified0 (String path)
boolean setLastModified0 (String path, long time)
boolean setReadOnly0 (String path)
long length0 (String filePath)
boolean mkdir0 (String path)
boolean newFile0 (String path) throws IOException
boolean rename0 (String pathExist, String pathNew)
String getAbsoluteName ()
void writeObject (ObjectOutputStream stream) throws IOException
void readObject (ObjectInputStream stream) throws IOException, ClassNotFoundException
FileSystemInfo getFileSystemInfo (String path)
FileSystemInfo getFileSystemInfoForDirectory (String path)
FileSystemInfo getFileSystemInfoForFile (String path)
boolean delete0 (String path)
String fixSlashes (String origPath)
 The purpose of this method is to take a path and fix the slashes up.

Static Private Member Functions

static synchronized String[] list0 (String absPath)
static File genTempFile (String prefix, String suffix, File directory)
static boolean isCaseSensitive ()

Private Attributes

String path
String absPath

Static Private Attributes

static final long serialVersionUID = 301077366599181567L
static final String EMPTY_STRING = ""
static int counter
static boolean caseSensitive

Constructor & Destructor Documentation

File ( File  dir,
String  name 
)

Constructs a new File using the specified directory and name.

Parameters:
dir the directory for the file name
name the file name to be contained in the dir

File ( String  path  ) 

Constructs a new File using the specified path.

Parameters:
path the path to be used for the file

File ( String  dirPath,
String  name 
)

Constructs a new File using the specified directory and name placing a path separator between the two.

Parameters:
dirPath the directory for the file name
name the file name to be contained in the dir

File ( URI  uri  ) 

Constructs a new File using the path of the specified URI.

uri needs to be an absolute and hierarchical URI with file scheme, and non-empty path component, but with undefined authority, query or fragment components.

Parameters:
uri the URI instance which will be used to construct this file
Exceptions:
IllegalArgumentException if uri does not comply with the conditions above.
See also:
toURI

java.net.URI


Member Function Documentation

[static initializer] (  )  [static, package]

void checkURI ( URI  uri  )  [private]

static File [] listRoots (  )  [static]

Lists the filesystem roots.

The Java platform may support zero or more filesystems, each with its own platform-dependent root. Further, the canonical pathname of any file on the system will always begin with one of the returned filesystem roots.

Returns:
the array of filesystem roots

boolean canRead (  ) 

Answers a boolean indicating whether or not the current context is allowed to read this File.

Returns:
true if this File can be read, false otherwise.
See also:
java.lang.SecurityManager.checkRead(FileDescriptor)

boolean canWrite (  ) 

Answers a boolean indicating whether or not the current context is allowed to write to this File.

Returns:
true if this File can be written, false otherwise.
See also:
java.lang.SecurityManager.checkWrite(FileDescriptor)

int compareTo ( File  another  ) 

Answers the relative sort ordering of paths for the receiver and given argument.

The ordering is platform dependent.

Parameters:
another a File to compare the receiver to
Returns:
an int determined by comparing the two paths. The meaning is described in the Comparable interface.
See also:
Comparable

boolean delete (  ) 

Deletes the file specified by this File.

Directories must be empty before they will be deleted.

Returns:
true if this File was deleted, false otherwise.
See also:
java.lang.SecurityManager.checkDelete

void deleteOnExit (  ) 

When the virtual machine terminates, any abstract files which have been sent deleteOnExit() will be deleted.

This will only happen when the virtual machine terminates normally as described by the Java Language Specification section 12.9.

boolean equals ( Object  obj  ) 

Compares the argument obj to the receiver, and answers true if they represent the same object using a path specific comparison.

Parameters:
obj the Object to compare with this Object
Returns:
true if the object is the same as this object, false otherwise.

boolean exists (  ) 

Answers a boolean indicating whether or not this File can be found on the underlying file system.

Returns:
true if this File exists, false otherwise.
See also:
getPath

java.lang.SecurityManager.checkRead(FileDescriptor)

Reimplemented in WinFile.

String getAbsolutePath (  ) 

Answers the absolute file path of this File.

Returns:
the absolute file path
See also:
java.lang.SecurityManager.checkPropertyAccess

File getAbsoluteFile (  ) 

Answers a new File constructed using the absolute file path of this File.

Returns:
a new File from this absolute file path
See also:
java.lang.SecurityManager.checkPropertyAccess

String getCanonicalPath (  )  throws IOException

Answers the absolute file path of this File with all references resolved.

An absolute file path is one which begins at the root of the file system. The canonical path is one in which all references have been resolved. For the cases of '..' and '.' where the file system supports parent and working directory respectively, these should be removed and replaced with a direct directory reference. If the File does not exist, getCanonicalPath() may not resolve any references and simply return an absolute path name or throw an IOException.

Returns:
the canonical file path
Exceptions:
IOException if an IO error occurs
See also:
java.lang.SecurityManager.checkPropertyAccess

File getCanonicalFile (  )  throws IOException

Answers a new File created using the canonical file path of this File.

Equivalent to new File(this.getCanonicalPath()).

Returns:
the canonical file path
Exceptions:
IOException If an IO error occurs
See also:
java.lang.SecurityManager.checkPropertyAccess

String getName (  ) 

Answers the filename (not directory) of this File.

Returns:
the filename or empty string

String getParent (  ) 

Answers the pathname of the parent of this File.

This is the path up to but not including the last name. null is returned when there is no parent.

Returns:
the parent name or null

File getParentFile (  ) 

Answers a new File made from the pathname of the parent of this File.

This is the path up to but not including the last name. null is returned when there is no parent.

Returns:
a new File representing parent or null

Reimplemented in WinFile.

String getPath (  ) 

Answers the file path of this File.

Returns:
the file path

int hashCode (  ) 

Answers an integer hash code for the receiver.

Any two objects which answer true when passed to equals must answer the same value for this method.

Returns:
the receiver's hash
See also:
equals

boolean isAbsolute (  ) 

Answers if this File is an absolute pathname.

Whether a pathname is absolute is platform specific. On UNIX it is if the path starts with the character '/', on Windows it is absolute if either it starts with '\', '/', '\' (to represent a file server), or a letter followed by a colon.

Returns:
true if this File is absolute, false otherwise.
See also:
getPath

boolean isDirectory (  ) 

Answers if this File represents a directory on the underlying file system.

Returns:
true if this File is a directory, false otherwise.
See also:
getPath

java.lang.SecurityManager.checkRead(FileDescriptor)

Reimplemented in WinFile.

boolean isFile (  ) 

Answers if this File represents a file on the underlying file system.

Returns:
true if this File is a file, false otherwise.
See also:
getPath

java.lang.SecurityManager.checkRead(FileDescriptor)

boolean isHidden (  ) 

Returns whether or not this file is a hidden file as defined by the operating system.

Returns:
true if the file is hidden, false otherwise.

Reimplemented in WinFile, and PlatformFile.

boolean isHidden0 ( String  path  )  [private]

long lastModified (  ) 

Answers the time this File was last modified.

Returns:
the time this File was last modified.
See also:
getPath

java.lang.SecurityManager.checkRead(FileDescriptor)

long lastModified0 ( String  path  )  [private]

boolean setLastModified ( long  time  ) 

Sets the time this File was last modified.

Parameters:
time The time to set the file as last modified.
Returns:
the time this File was last modified.
See also:
java.lang.SecurityManager.checkWrite(FileDescriptor)

boolean setLastModified0 ( String  path,
long  time 
) [private]

boolean setReadOnly (  ) 

Marks this file or directory to be read-only as defined by the operating system.

Returns:
true if the operation was a success, false otherwise

boolean setReadOnly0 ( String  path  )  [private]

long length (  ) 

Answers the length of this File in bytes.

Returns:
the number of bytes in the file.
See also:
getPath

java.lang.SecurityManager.checkRead(FileDescriptor)

long length0 ( String  filePath  )  [private]

String [] list (  ) 

Answers an array of Strings representing the file names in the directory represented by this File.

If this File is not a directory the result is null.

The entries . and .. representing current directory and parent directory are not returned as part of the list.

Returns:
an array of Strings or null.
See also:
getPath

isDirectory

java.lang.SecurityManager.checkRead(FileDescriptor)

File [] listFiles (  ) 

Answers an array of Files representing the file names in the directory represented by this File.

If this File is not a directory the result is null. The Files returned will be absolute if this File is absolute, relative otherwise.

Returns:
an array of Files or null.
See also:
getPath

list()

isDirectory

Reimplemented in WinFile.

File [] listFiles ( FilenameFilter  filter  ) 

Answers an array of Files representing the file names in the directory represented by this File that match a specific filter.

If this File is not a directory the result is null. If the filter is null then all filenames match.

The entries . and .. representing current directory and parent directory are not returned as part of the list.

Parameters:
filter the filter to match names to or null.
Returns:
an array of Files or null.
See also:
list(FilenameFilter filter)

getPath

isDirectory

java.lang.SecurityManager.checkRead(FileDescriptor)

File [] listFiles ( FileFilter  filter  ) 

Answers an array of Files representing the file names in the directory represented by this File that match a specific filter.

If this File is not a directory the result is null. If the filter is null then all filenames match.

The entries . and .. representing current directory and parent directory are not returned as part of the list.

Parameters:
filter the filter to match names to or null.
Returns:
an array of Files or null.
See also:
getPath

isDirectory

java.lang.SecurityManager.checkRead(FileDescriptor)

String [] list ( FilenameFilter  filter  ) 

Answers an array of Strings representing the file names in the directory represented by this File that match a specific filter.

If this File is not a directory the result is null. If the filter is null then all filenames match.

The entries . and .. representing current directory and parent directory are not returned as part of the list.

Parameters:
filter the filter to match names to or null.
Returns:
an array of Strings or null.
See also:
getPath

isDirectory

java.lang.SecurityManager.checkRead(FileDescriptor)

static synchronized String [] list0 ( String  absPath  )  [static, private]

boolean mkdir (  ) 

Creates the directory named by the trailing filename of this File.

Not all directories required to create this File are created.

Returns:
true if the directory was created, false otherwise.
See also:
getPath

java.lang.SecurityManager.checkWrite(FileDescriptor)

boolean mkdir0 ( String  path  )  [private]

boolean mkdirs (  ) 

Create all the directories needed for this File.

If the terminal directory already exists, answer false. If the directories were created successfully, answer true.

Returns:
true if the necessary directories were created, false otherwise.

boolean createNewFile (  )  throws IOException

Creates the file specified by this File.

If the file already exists this method returns false. Otherwise, if the file is created successfully, the result is true. An IOException will be thrown if the directory to contain this file does not exist.

Returns:
true if this File was created, false otherwise.
Exceptions:
IOException if an I/O error occurs or the directory does not exist.
See also:
java.lang.SecurityManager.checkWrite(FileDescriptor)

boolean newFile0 ( String  path  )  throws IOException [private]

static File createTempFile ( String  prefix,
String  suffix 
) throws IOException [static]

Creates an empty temporary file using the given prefix and suffix as part of the file name.

If suffix is null, .tmp is used.

Parameters:
prefix the prefix to the temp file name
suffix the suffix to the temp file name
Returns:
the temporary file
Exceptions:
IOException If an error occurs when writing the file

static File createTempFile ( String  prefix,
String  suffix,
File  directory 
) throws IOException [static]

Creates an empty temporary file in the given directory using the given prefix and suffix as part of the file name.

Parameters:
prefix the prefix to the temp file name
suffix the suffix to the temp file name
directory the location to which the temp file is to be written, or null for the default temp location
Returns:
the temporary file
Exceptions:
IOException If an error occurs when writing the file

static File genTempFile ( String  prefix,
String  suffix,
File  directory 
) [static, private]

boolean renameTo ( File  dest  ) 

Renames this File to the name represented by the File dest.

This works for both normal files and directories.

Parameters:
dest the File containing the new name.
Returns:
true if the File was renamed, false otherwise.
See also:
getPath

java.lang.SecurityManager.checkRead(FileDescriptor)

java.lang.SecurityManager.checkWrite(FileDescriptor)

boolean rename0 ( String  pathExist,
String  pathNew 
) [private]

String toString (  ) 

Answers a string containing a concise, human-readable description of the receiver.

Returns:
a printable representation for the receiver.

Reimplemented in WinFile.

URI toURI (  ) 

Answers a file URI for this File.

The URI is System dependent and may not be transferable between different operating/file systems.

Returns:
a file URI for this File.

URL toURL (  )  throws java.net.MalformedURLException

Answers a file URL for this File.

The URL is System dependent and may not be transferable between different operating/file systems.

Returns:
a file URL for this File.
Exceptions:
java.net.MalformedURLException if the path cannot be transformed into an URL

String getAbsoluteName (  )  [private]

void writeObject ( ObjectOutputStream  stream  )  throws IOException [private]

void readObject ( ObjectInputStream  stream  )  throws IOException, ClassNotFoundException [private]

FileSystemInfo getFileSystemInfo ( String  path  )  [private]

FileSystemInfo getFileSystemInfoForDirectory ( String  path  )  [private]

FileSystemInfo getFileSystemInfoForFile ( String  path  )  [private]

boolean delete0 ( String  path  )  [private]

static boolean isCaseSensitive (  )  [static, private]

String fixSlashes ( String  origPath  )  [private]

The purpose of this method is to take a path and fix the slashes up.

This includes changing them all to the current platforms fileSeparator and removing duplicates.


Member Data Documentation

final long serialVersionUID = 301077366599181567L [static, private]

final String EMPTY_STRING = "" [static, private]

String path [private]

String absPath [private]

final char separatorChar [static]

System dependent file separator character.

final String separator [static]

System dependent file separator String.

The initial value of this field is the System property "file.separator".

final char pathSeparatorChar [static]

System dependent path separator character.

final String pathSeparator [static]

System dependent path separator String.

The initial value of this field is the System property "path.separator".

int counter [static, private]

boolean caseSensitive [static, private]