public class File extends Object implements FileConstants, Textable, FilePermissions
1. It is mutable - the set() methods can be used to change the File that it refers to.
2. It may be overridden so that it does not access any local File resources at all.
However if you are doing that, it is better to override FileAdapter instead to ensure
that you do not use any local File system resources.
Modifier and Type | Field and Description |
---|---|
protected CharArray |
name |
ClosedFolderIcon, DOS_SYSTEM, DriveIcon, FileIcon, FLAG_CASE_SENSITIVE, FLAG_FILE_SYSTEM_IS_READ_ONLY, FLAG_IS_NETWORK_COMPUTER, FLAG_IS_NETWORK_ROOT, FLAG_IS_ON_NETWORK, FLAG_READ_ONLY, FLAG_SLOW_ACCESS, FLAG_SLOW_CHILD_COUNT, FLAG_SLOW_LIST, INFO_CREATE_TEMP, INFO_CURRENT_DIRECTORY, INFO_DETAIL_NAMES, INFO_DETAIL_WIDTHS, INFO_DETAILS, INFO_DEVICE_ICON, INFO_DEVICE_NAME, INFO_FILE_TIMES, INFO_FLAGS, INFO_FREE_DRIVE_SPACE, INFO_GROUP, INFO_ICON, INFO_LINK_DESTINATION, INFO_OPTION_ICON_LARGE, INFO_OPTION_ICON_MEDIUM, INFO_OPTION_ICON_SMALL, INFO_OWNER, INFO_PROGRAM_DIRECTORY, INFO_ROOT_LIST, INFO_SET_USER_AND_GROUP, INFO_SYMBOLIC_LINK_TARGET, INFO_SYSTEM_TYPE, INFO_TEMPORARY_DIRECTORY, INFO_TOOL_TIP, INFO_TOTAL_DRIVE_SPACE, INFO_VOLUME_FLAGS, INFO_VOLUME_LIST, INFO_VOLUME_PROPERTIES, LIST_ALWAYS_INCLUDE_DIRECTORIES, LIST_BY_DATE, LIST_BY_NAME, LIST_BY_SIZE, LIST_BY_TYPE, LIST_CHECK_FOR_ANY_MATCHING_CHILDREN, LIST_DESCENDING, LIST_DIRECTORIES_FIRST, LIST_DIRECTORIES_LAST, LIST_DIRECTORIES_ONLY, LIST_DONT_LIST_HIDDEN_FILES, LIST_DONT_SORT, LIST_FILES_ONLY, LIST_IGNORE_DIRECTORY_STATUS, MEMORY_SYSTEM, OpenFolderIcon, PageIcon, PALM_SYSTEM, pathSeparator, pathSeparatorChar, separator, separatorChar, UNIX_SYSTEM
VOLUME_FLAG_CDROM, VOLUME_FLAG_FIXED, VOLUME_FLAG_NETWORK, VOLUME_FLAG_RAM, VOLUME_FLAG_REMOVABLE, VOLUME_PROPERTY_BYTES_FREE, VOLUME_PROPERTY_BYTES_TOTAL, VOLUME_PROPERTY_FILESYSTEM_NAME, VOLUME_PROPERTY_NAME
ALL_DOS_FLAGS, ALL_UNIX_PERMISSIONS, FLAG_ARCHIVE, FLAG_HIDDEN, FLAG_READONLY, FLAG_ROM, FLAG_ROMMODULE, FLAG_SYSTEM, FLAG_WINDOWS_ALL_USERS_ACCESS, GROUP_EXECUTE, GROUP_READ, GROUP_WRITE, OTHER_EXECUTE, OTHER_READ, OTHER_WRITE, OWNER_EXECUTE, OWNER_READ, OWNER_WRITE
Modifier | Constructor and Description |
---|---|
protected |
File() |
|
File(File file) |
|
File(File dir,
String file) |
|
File(File directory,
String path) |
|
File(String name) |
Modifier and Type | Method and Description |
---|---|
protected String |
_jfilegetAbsolutePath() |
boolean |
allowAllUsersFullAccess()
This special operation allows all users of a Windows or Unix machine full Read/Write/Excecute access to a file or directory.
|
boolean |
canRead()
Returns true if the file exists and can be read.
|
boolean |
canWrite() |
boolean |
changePermissionsAndFlags(int valuesToSet,
int valuesToClear)
Change ther permissions/flags for this File - see ewe.io.FilePermissions for a list of
the available flag permissions.
|
int |
chmod(int newPermissions)
Perform a Unix like chmod changing all the unix owner/group/other permissions
in one operation.
|
boolean |
chown(String newUser,
String newGroup)
Change the user and group if supported.
|
boolean |
createDir() |
boolean |
createNewFile()
This method creates a new file of zero length with the same name as
the path of this
File object if an only if that file
does not already exist. |
boolean |
createSymbolicLink(String target)
Create a symbolic link to a specified target file.
|
File |
createTempFile(String fileName,
File dir)
This creates an empty file with a specific name in a temporary directory.
|
File |
createTempFile(String prefix,
String suffix,
File dir)
This creates an empty temporary file with the specified prefix and suffix.
|
boolean |
delete() |
void |
deleteOnExit() |
boolean |
equals(Object other)
This checks to see if the two files refer to the same object in the file
system.
|
boolean |
exists() |
boolean |
filePathsAreEqual(String one,
String two) |
static String |
fixupPath(String path) |
File |
getAbsoluteFile() |
String |
getAbsolutePath()
This differs from getFullPath() in that this will convert all '\' characters
to '/' characters.
|
Object |
getBestFileChooser(FileChooserParameters fcp) |
File |
getCanonicalFile() |
String |
getCanonicalPath() |
File |
getChild(String path) |
File |
getChild(String path,
File destination)
Set the destination to be the specified child of this File.
|
File |
getCopy() |
String |
getCreationName()
Return the file's path, as specified when created.
|
CharArray |
getCreationName(CharArray dest)
Return the file's path, as specified when created.
|
String |
getDefaultRoot() |
String |
getDrivePath()
Return only the drive and path of the file.
|
static String |
getDrivePath(String str) |
String |
getFileExt()
Return only the filename and extension of the file.
|
static String |
getFileExt(String str) |
int |
getFlags()
A quick way to get the flags from getInfo().
|
String |
getFullPath() |
String |
getGroup()
Get the group name of the file or null if that is
not supported on the platform.
|
static Object |
getIcon(int whichIcon)
Get one of the icons: OpenFolderIcon, ClosedFolderIcon and PageIcon.
|
Wrapper |
getInfo(int infoCode)
A quick way of doing getInfo(infoCode,null,null,0);
|
Wrapper |
getInfo(int infoCode,
Wrapper sourceParameters,
int options) |
long |
getLength() |
Time |
getModified(Time dest)
Get the Time that the file was last modified.
|
String |
getName() |
File |
getNew(File directory,
String path)
Get a new File object given the directory and new path.
|
File |
getNew(String path)
Get a new File object given the directory and new path.
|
static File |
getNewFile()
Get a new File object for the default file system used by the VM.
|
static File |
getNewFile(File directory,
String name)
Get a new File object for the default file system used by the VM.
|
static File |
getNewFile(String name)
Get a new File object for the default file system used by the VM.
|
protected File |
getNewInstance() |
String |
getOwner()
Get the owner user name of the file or null if that is
not supported on the platform.
|
String |
getParent() |
File |
getParentFile()
Get a File object representing the parent direcotry of this File.
|
int |
getPermissionsAndFlags(int interestedFlags)
Get ther permissions/flags for this File - see ewe.io.FilePermissions for a list of
the available flag permissions.
|
static String |
getProgramDirectory()
A quick way to get the program directory for the application.
|
String |
getPropertiesString() |
protected Wrapper |
getSetInfo(int infoCode,
Wrapper sourceParameters,
int options,
boolean isGet) |
protected long |
getSetModified(long time,
boolean doGet) |
protected int |
getSetPermissionsAndFlags(boolean isGet,
int valuesToSetOrGet,
int valuesToClear)
This is used to implement getPermissionsAndFlags() and changePermissionsAndFlags().
|
int |
getSupportedPermissionsAndFlags(int interestedFlags)
Returns a value indicating which of the flags
specified in the interestedFlags parameter is supported by the
underlying system.
|
File |
getSymbolicLinkTarget()
If this file is a symbolic link, return the target of the link.
|
String |
getText() |
static String |
getTrueChild(File parent,
String child,
File aFile) |
static File |
getTrueParent(File parent,
String child,
File aFile) |
int |
hashCode()
Returns a hashCode for the object.
|
boolean |
isAbsolute()
Checks if the name of the file as specified during creation is an absolute file name.
|
boolean |
isDirectory() |
boolean |
isFile() |
boolean |
isHidden() |
boolean |
isSameFileSystem(File other)
Returns true if the other file system is considered the same as this one.
|
boolean |
isSameVolume(File other)
Checks if the volume which contains the other File is considered the same as the one that
contains this File.
|
boolean |
isSymbolicLink() |
long |
lastModified()
Return the time the file was last modified - but this method is not as powerful
as getModified().
|
String[] |
list()
Lists all files on the directory that this File object
represents, sorted by name - with directories listed first.
|
String[] |
list(FilenameFilter filter)
List all files in this directory using the specified filter.
|
String[] |
list(String mask,
int listAndSortOptions)
Lists the files contained in a directory.
|
CharArray |
list(String mask,
int listAndSortOptions,
CharArray dest) |
String[] |
listMultiple(String compositeMask,
int listAndSortOptions)
Lists the files contained in a directory using a complex mask - which
may actually consist of multiple masks (e.g. "*.jpg,*.gif - Image Files.").
|
static File[] |
listRoots()
List all the root files in the default file system.
|
static File[] |
listVolumes()
List all the volumes in the default file system.
|
static String |
makePath(File parent,
String child)
Utility to create a path name given a parent and child.
|
static String |
makePath(String parent,
String child)
Utility to create a path name given a parent and child.
|
boolean |
mkdir() |
boolean |
mkdirs()
Create a directory and all necessary parent directories.
|
boolean |
move(File newFile) |
Handle |
refresh()
This tells the File system to consider any cached directory invalid so
so that a list() call will do a true lookup.
|
static CharArray |
removeTrailingSlash(CharArray ca) |
static String |
removeTrailingSlash(String path) |
boolean |
rename(String newName)
This renames the file in place.
|
boolean |
renameTo(File newFile) |
File[] |
roots()
List the Files that are considered "root" file systems.
|
void |
set(File directory,
String path)
Modifies the File to point to a different file on the file system.
|
boolean |
setExecutable(boolean executable,
boolean ownerOnly) |
boolean |
setInfo(int infoCode,
Wrapper sourceParameters,
int options) |
void |
setJavaFile(File file) |
void |
setJavaFile(File dir,
String file) |
boolean |
setLastModified(long time)
Set the time the file was last modified - but this method is not as powerful
as setModified().
|
void |
setModified(Time modifiedTime)
Set the Time the file was last modified.
|
int |
setPermissionsAndFlags(int valuesToSet,
int valuesToClear)
Change the permissions/flags for this File - see eve.io.FilePermissions for a list of
the available flag permissions.
|
boolean |
setReadable(boolean readable,
boolean ownerOnly) |
boolean |
setReadOnly() |
void |
setText(String text) |
boolean |
setWritable(boolean writable,
boolean ownerOnly) |
File |
toJavaFile() |
RandomStream |
toRandomStream(String mode)
Create and return a RandomAccessStream for reading/writing to the data associated with this File object.
|
InputStream |
toReadableStream()
Create and return a Stream to use for reading from the File.
|
String |
toString()
Return a String representation of this object.
|
static String |
toSystemDependantPath(String path)
This converts any '/' directory separators to the one that is native to the running OS (ie '\' on Windows)
and any ';' path separtors to the one that is native to the running OS (ie ':' on Unix/Linux).
|
OutputStream |
toWritableStream(boolean append)
Create and return a Stream to use for writing to the File.
|
int |
volumeFlags()
Assuming this File object represents a volume, get the known flags for the volume.
|
PropertyList |
volumeProperties() |
File[] |
volumes()
List the Files that are considered distinct volumes on the file system.
|
protected CharArray name
public Object getBestFileChooser(FileChooserParameters fcp)
public File createTempFile(String prefix, String suffix, File dir)
public File createTempFile(String fileName, File dir)
public static Object getIcon(int whichIcon)
public File getNew(File directory, String path)
public String[] list(String mask, int listAndSortOptions)
The default method calls the list() method and then splits the returned char array.
mask
- A file mask.listAndSortOptions
- Use the LIST_XXX values OR'ed together.public String[] listMultiple(String compositeMask, int listAndSortOptions)
compositeMask
- A possibly complex file mask.listAndSortOptions
- Use the LIST_XXX values OR'ed together.public static String toSystemDependantPath(String path)
Your initial constructed path(s) SHOULD use '/' for directories and ';' for path separators.
This is generally only necessary for a few system dependant functions and is not necessary for standard file access.
public boolean renameTo(File newFile)
public long lastModified()
public boolean setLastModified(long time)
time
- the time in milliseconds to set the modified time to.public String[] list()
public String[] list(FilenameFilter filter)
filter
- The filter to use for accepting/rejecting files.public File getNew(String path)
public File getChild(String path, File destination)
path
- the child of this file.destination
- an optional destination File. If it is null then a new one is created
and returned.public File getCopy()
public boolean canRead()
public boolean isFile()
public final String getCreationName()
public CharArray getCreationName(CharArray dest)
public boolean isAbsolute()
public String getFileExt()
public String getDrivePath()
public static String makePath(File parent, String child)
parent
- The parent File - which may be null.child
- The child name.public static String makePath(String parent, String child)
parent
- The parent path - which may be null.child
- The child name.public String getParent()
public File getParentFile()
public boolean rename(String newName)
public Time getModified(Time dest) throws IOException
dest
- an optional destination Time object to hold the time.IOException
- if an error occurs getting the time.public void setModified(Time modifiedTime) throws IOException
modifiedTime
- the Time to set the modified time to. If this is null then the
current time will be used.IOException
- if an error occurs setting the time.public Wrapper getInfo(int infoCode)
infoCode
- one of the INFO_XXX values.public int getFlags()
public static String getProgramDirectory()
public File[] roots()
public File[] volumes()
public static File[] listRoots()
public static File[] listVolumes()
public int volumeFlags()
public PropertyList volumeProperties()
public boolean mkdirs()
public boolean mkdir()
public String toString()
Object
public boolean equals(Object other)
public int hashCode()
Object
public String getAbsolutePath()
public File getAbsoluteFile()
public String getCanonicalPath() throws IOException
IOException
public File getCanonicalFile() throws IOException
IOException
public String getName()
public Handle refresh()
public boolean isSameFileSystem(File other)
other
- another File object representing a File on a possibly different file system.public boolean isSameVolume(File other)
other
- another File object representing a File on a possibly different volume.public InputStream toReadableStream() throws IOException
IOException
- if an open stream could not be created.public OutputStream toWritableStream(boolean append) throws IOException
append
- set this true if you want to append to the existing file.IOException
- if an open stream could not be created, or if the file exists but could not
be written to or erased (if not appending), or if you requested append but append mode is not supported
for this File.public RandomStream toRandomStream(String mode) throws IOException
mode
- must be "r" or "rw".IOException
- if an open stream could not be created.IllegalArgument
- exception if mode is not "r" or "rw"public static File getNewFile()
public static File getNewFile(String name)
public static File getNewFile(File directory, String name)
public int getPermissionsAndFlags(int interestedFlags) throws IOException, IllegalArgumentException
interestedFlags
- The flags whose values you are interested in.IOException
- if the file does not exist or some other error occured.IllegalArgumentException
- if one of the flags you are interested in is not supported
on this file system.public boolean changePermissionsAndFlags(int valuesToSet, int valuesToClear) throws IOException, IllegalArgumentException
valuesToSet
- The permissions/flags to set.valuesToClear
- The permissions/flags to clear.IOException
- if the file does not exist or some other IO error occured.IllegalArgumentException
- if one of the flag values is not supported.public boolean allowAllUsersFullAccess() throws IOException
IOException
protected int getSetPermissionsAndFlags(boolean isGet, int valuesToSetOrGet, int valuesToClear) throws IOException
If isGet is true, then the valuesToSetOrGet parameter will hold the flags that the user is interested in. If any of these flags are invalid on this system an IllegalArgumentException should be thrown. Otherwise the current state of the flags should be returned - it is OK to return extra flags even if they are not specified as flags the user is interested in.
If isGet is false, then the valuesToSetOrGet parameter will hold the flags to set and the valuesToClear parameter will hold the flags to clear. If any of these are not valid then an IllegalArgumentException should be thrown. Otherwise the flags should be changed and then the state of the flags AFTER the change has been made should be returned.
IOException
public int getSupportedPermissionsAndFlags(int interestedFlags)
interestedFlags
- the flags you wish to check OR'ed together.public int setPermissionsAndFlags(int valuesToSet, int valuesToClear) throws IOException, IllegalArgumentException
valuesToSet
- The permissions/flags to set.valuesToClear
- The permissions/flags to clear.IOException
- if the file does not exist or some other IO error occured.IllegalArgumentException
public int chmod(int newPermissions) throws IOException
newPermissions
- the new state for all the owner/group/other permissions.IOException
- if an IO error occured while changing the permissions. If
the method fails because the current process does not have the rights to change
the file, the method NOT throw an exception.public boolean chown(String newUser, String newGroup) throws IOException
newUser
- the new user name. This can be null if newGroup is not null.newGroup
- the new group name. This can be null if newUser is not null.IOException
- if there an IO error occured.NullPointerException
- if both newUser and newGroup is null.public boolean createSymbolicLink(String target)
target
- the file to link to.public File getSymbolicLinkTarget()
public String getOwner()
public String getGroup()
public String getPropertiesString()
public void set(File directory, String path)
public void setJavaFile(File file)
protected String _jfilegetAbsolutePath()
protected File getNewInstance()
public boolean createDir()
public boolean delete()
public boolean exists()
public boolean canWrite()
public boolean isHidden()
public boolean isDirectory()
public boolean isSymbolicLink()
public String getFullPath()
public void deleteOnExit()
public boolean createNewFile() throws IOException
File
object if an only if that file
does not already exist.
A SecurityManager
checkWrite check is done prior
to performing this action.
true
if the file was created, false
if
the file alread existed.IOException
- If an I/O error occursSecurityException
- If the SecurityManager
will
not allow this operation to be performed.public CharArray list(String mask, int listAndSortOptions, CharArray dest) throws IOException
IOException
protected long getSetModified(long time, boolean doGet) throws IOException
IOException
public boolean move(File newFile)
protected Wrapper getSetInfo(int infoCode, Wrapper sourceParameters, int options, boolean isGet) throws IOException
IOException
public Wrapper getInfo(int infoCode, Wrapper sourceParameters, int options) throws IOException
IOException
public boolean setInfo(int infoCode, Wrapper sourceParameters, int options)
public File toJavaFile()
public long getLength()
public boolean setExecutable(boolean executable, boolean ownerOnly)
public boolean setReadable(boolean readable, boolean ownerOnly)
public boolean setWritable(boolean writable, boolean ownerOnly)
public boolean setReadOnly()
public final String getDefaultRoot()