All Packages Class Hierarchy This Package Previous Next Index
Class com.ibm.as400.access.IFSJavaFile
java.lang.Object
|
+----java.io.File
|
+----com.ibm.as400.access.IFSJavaFile
- public class IFSJavaFile
- extends File
- implements Serializable
The IFSJavaFile class represents a file in the AS/400
integrated file system.
IFSJavaFile extends the java.io.File class and allows programs
to be written for the java.io.File interface and still access
the AS/400 integrated file system.
IFSFile should be considered as an alternate to this class.
When should IFSJavaFile be used?
-
IFSJavaFile should be used when a portable interface, compatible with
java.io.File, is needed. For example, you have written code
that accesses the native file system. Now you want to move
the design to a networked file system. More particularly,
you need to move the code to the AS/400 integrated file system.
When a program is being ported and needs to use the AS/400
integrated file system, IFSJavaFile is a good choice.
IFSJavaFile also provides SecurityManager features defined in
java.io.File.
-
If you need to take full advantage of the AS/400 integrated file
system, IFSFile is more useful. IFSFile is written to
handle more of the specific AS/400 integrated file system details.
-
java.io.File can be used to access the AS/400 file system
if you use a product like Client Access/400 to map a local drive
to the AS/400 integrated file system.
Notes:
- IFSJavaFile is designed to be used with
IFSFileInputStream and IFSFileOutputStream.
It does not support java.io.FileInputStream
and java.io.FileOutputStream.
- IFSJavaFile cannot override createTempFile because
java.io.File defines createTempFile as a static method.
- IFSJavaFile cannot override deleteOnExit because the
Java Virtual Machine does nothing to indicate when it
is preparing to exit.
- IFSJavaFile is designed to look more like
java.io.File than IFSFile. It is designed to enable
a plug-in fit for previously written java.io.File code.
- IFSJavaFile always implements a SecurityManager using
AS/400 security. The SecurityManager provides authority
checks. It throws security exceptions when illegal access
attempts are made.
The following example demonstrates the use of IFSJavaFile. It shows how a few lines
of platform specific code enable the creation of a file on either the AS/400 or
the local client.
int location = ON_THE_AS400;
java.io.File file = null;
java.io.OutputStream os = null;
if (location == ON_THE_AS400)
file = new IFSJavaFile(new AS400("enterprise"), path); // Work with the file on the system "enterprise".
else
file = new java.io.File (path); // Work with the file on the local file system.
if (file.exists())
System.out.println ("Length: " + file.length()); // Determine the file size.
else
System.out.println ("File " + file.getName() + " not found");
// Delete the file. This should be done before creating an output stream.
if (file.delete() == false)
System.err.println("Unable to delete file."); // Display the error message.
if (location == ON_THE_AS400)
os = (OutputStream)new IFSFileOutputStream((IFSJavaFile)file);
else
os = new FileOutputStream (file);
writeData(file, os);
os.close();
void writeData (java.io.File file, java.io.OutputStream os)
throws IOException
{
// Determine the parent directory of the file.
System.out.println ("Directory: " + file.getParent());
// Determine the name of the file.
System.out.println ("Name: " + file.getName());
// Determine when the file was last modified.
System.out.println ("Date: " + new Date(file.lastModified()));
System.out.println ("Writing Data");
for (int i = 0; i < 256; i++)
os.write ((byte)i);
}
- See Also:
- IFSFile, IFSFileInputStream, IFSFileOutputStream
-
IFSJavaFile()
- Constructs an IFSJavaFile object.
-
IFSJavaFile(AS400, IFSJavaFile, String)
- Constructs an IFSJavaFile object.
-
IFSJavaFile(AS400, String)
- Constructs an IFSJavaFile object.
-
IFSJavaFile(AS400, String, String)
- Constructs an IFSJavaFile object.
-
IFSJavaFile(IFSJavaFile, String)
- Constructs an IFSJavaFile object.
-
canRead()
- Indicates if the program can read from the IFSJavaFile.
-
canWrite()
- Indicates if the program can write to the IFSJavaFile.
-
compareTo(IFSJavaFile)
- Compares the paths of two IFSJavaFiles.
-
compareTo(Object)
-
Compares the path of IFSJavaFile with
Object's
path.
-
delete()
- Deletes the IFSJavaFile.
-
equals(Object)
- Compares this IFSJavaFile against the
specified object.
-
exists()
- Indicates if the IFSJavaFile exists.
-
getAbsolutePath()
- Returns the absolute path name of the IFSJavaFile.
-
getCanonicalPath()
- Returns the path name in canonical form of IFSJavaFile path.
-
getName()
- Returns the name of the IFSJavaFile.
-
getParent()
- Returns the parent directory of the IFSJavaFile.
-
getPath()
- Returns the path name of the IFSJavaFile.
-
getSystem()
- Returns the system that this object references.
-
hashCode()
- Computes a hashcode for this object.
-
isAbsolute()
- Indicates if the path name of this IFSJavaFile is an
absolute path name.
-
isDirectory()
- Indicates if the IFSJavaFile is a directory.
-
isFile()
- Indicates if the IFSJavaFile is a "normal" file.
A file is "normal" if it is not a directory or a container of other objects.
-
lastModified()
- Indicates the time that the IFSJavaFile was last modified.
-
length()
- Indicates the length of this IFSJavaFile.
-
list()
- Lists the files in this IFSJavaFile directory.
-
list(FilenameFilter)
- Lists the files in this IFSJavaFile directory that satisfy filter.
-
list(IFSFileFilter)
- Lists the files in the IFSJavaFile directory that satisfy file name filter.
-
list(IFSFileFilter, String)
- Lists the files in this IFSJavaFile directory that satisfy filter and pattern.
-
list(String)
- Lists the files in this IFSJavaFile directory that match pattern.
-
mkdir()
- Creates a directory whose path name
is specified by this IFSJavaFile.
-
mkdirs()
- Creates a directory whose path name is
specified by this IFSJavaFile, including any necessary
parent directories.
-
renameTo(IFSJavaFile)
- Renames the IFSJavaFile to have the path name of dest.
-
setPath(String)
- Sets the path for this IFSJavaFile.
-
setSystem(AS400)
- Sets the system.
-
toString()
- Returns a string representation of this object.
IFSJavaFile
public IFSJavaFile()
- Constructs an IFSJavaFile object.
It creates a default IFSJavaFile instance.
IFSJavaFile
public IFSJavaFile(AS400 system,
String path)
- Constructs an IFSJavaFile object.
It creates a
IFSJavaFile
on system that has a path name of path.
- Parameters:
- system - The AS400 that contains the IFSJavaFile.
- path - The file path name where the IFSJavaFile is or will be stored.
IFSJavaFile
public IFSJavaFile(AS400 system,
String path,
String name)
- Constructs an IFSJavaFile object.
It creates a IFSJavaFile on system that has a
path name of path, followed by the separator
character, followed by name.
- Parameters:
- system - The AS400 that contains the IFSJavaFile.
- path - The file path name where the IFSJavaFile is or will be stored.
- name - The name of the IFSJavaFile object.
IFSJavaFile
public IFSJavaFile(IFSJavaFile directory,
String name)
- Constructs an IFSJavaFile object.
It creates a
IFSJavaFile
with the specified name
in the specified directory.
The directory argument cannot be null
. The constructed
IFSJavaFile
instance uses the following settings taken from
directory:
The resulting file name is taken from the path name of directory,
followed by the separator character, followed by name.
- Parameters:
- directory - The directory where the IFSJavaFile is or will be stored.
- name - The name of the IFSJavaFile object.
- See Also:
- getPath
IFSJavaFile
public IFSJavaFile(AS400 system,
IFSJavaFile directory,
String name)
- Constructs an IFSJavaFile object.
It creates a IFSJavaFile on system
that has a path name of directory, followed
by the separator character, followed by name.
- Parameters:
- system - The AS400 that contains the IFSJavaFile.
- directory - The directory where the IFSJavaFile is or will be stored.
- name - The name of the IFSJavaFile object.
- See Also:
- getPath
canRead
public boolean canRead()
- Indicates if the program can read from the IFSJavaFile.
- Returns:
-
true
if the object exists and is readable; false
otherwise.
- Overrides:
- canRead in class File
canWrite
public boolean canWrite()
- Indicates if the program can write to the IFSJavaFile.
- Returns:
-
true
if the object exists and is writeable; false
otherwise.
- Overrides:
- canWrite in class File
compareTo
public int compareTo(IFSJavaFile file)
- Compares the paths of two IFSJavaFiles.
The following examples demonstrate the use of this method:
In this example, returnCode would be less than 0
because the
path of file
is less than the path of file2
.
IFSJavaFile file = new IFSJavaFile(new AS400("enterprise"), path);
IFSJavaFile file2 = new IFSJavaFile(new AS400("enterprise"), path + "\\extra");
int returnCode = file.compareTo (file2);
In this example, returnCode would be greater than 0
because the
path of file
is greater than the path of file2
.
IFSJavaFile file = new IFSJavaFile(new AS400("enterprise"), path + "\\extra");
IFSJavaFile file2 = new IFSJavaFile(new AS400("enterprise"), path);
int returnCode = file.compareTo (file2);
In this example, returnCode would be less than 0
because the
path of file
is less than the path of file2
.
IFSJavaFile file = new IFSJavaFile(new AS400("enterprise"), "\\QSYS.LIB\\herlib");
IFSJavaFile file2 = new IFSJavaFile(new AS400("enterprise"), "\\QSYS.LIB\\hislib");
int returnCode = file.compareTo (file2);
Note:
The comparison is case sensitive.
- Parameters:
- file - The
IFSJavaFile
to be compared.
- Returns:
-
0
if this IFSJavaFile path equals file's
path;
a value less than 0
if this IFSJavaFile path is less than the file's
path; and a value greater than 0
if this IFSJavaFile path is greater
than the file's
path.
compareTo
public int compareTo(Object obj)
- Compares the path of IFSJavaFile with
Object's
path.
If the Object is a IFSJavaFile, this function
behaves like compareTo(IFSJavaFile)
. Otherwise, it
throws a ClassCastException
(IFSJavaFiles are
comparable only to other IFSJavaFiles).
Note:
The comparison is case sensitive.
- Parameters:
- obj - The
Object
to be compared.
- Returns:
-
0
if this IFSJavaFile path equals the argument's path;
a value less than 0
if this IFSJavaFile path is less than the argument's
path; and a value greater than 0
if this IFSJavaFile path is greater
than the argument's path.
delete
public boolean delete()
- Deletes the IFSJavaFile. If the target is
a directory, it must be empty for deletion to succeed.
- Returns:
-
true
if the file is successfully deleted;
false
otherwise.
- Overrides:
- delete in class File
equals
public boolean equals(Object obj)
- Compares this IFSJavaFile against the
specified object.
Returns
true
if and only if the argument is
not null
and is a IFSJavaFile
object whose path name is equal to the path name of
this IFSJavaFile.
- Parameters:
- obj - The object to compare with.
- Returns:
-
true
if the objects are the same;
false
otherwise.
- Overrides:
- equals in class File
exists
public boolean exists()
- Indicates if the IFSJavaFile exists.
- Returns:
-
true
if the file specified by this object
exists; false
otherwise.
- Overrides:
- exists in class File
getAbsolutePath
public String getAbsolutePath()
- Returns the absolute path name of the IFSJavaFile.
This is the full path starting at the root directory.
- Returns:
- The absolute path name for this IFSJavaFile.
All paths are absolute paths in the integrated file system.
- Overrides:
- getAbsolutePath in class File
- See Also:
- isAbsolute
getCanonicalPath
public String getCanonicalPath() throws IOException
- Returns the path name in canonical form of IFSJavaFile path.
This is the full path starting at the root directory.
- Returns:
- The canonical path name for this IFSJavaFile.
- Throws: IOException
- If an I/O error occurs while communicating with the AS/400.
- Overrides:
- getCanonicalPath in class File
getName
public String getName()
- Returns the name of the IFSJavaFile. The name
is everything in the path name after the last occurrence of the
separator character.
The following example demonstrates the use of this method:
In this example, fileName would equal "file.dat".
String path = "\\path\\file.dat";
IFSJavaFile file = new IFSJavaFile(new AS400("enterprise"), path);
String fileName = file.getName();
- Returns:
- The name (without any directory components) of this
IFSJavaFile
.
- Overrides:
- getName in class File
getParent
public String getParent()
- Returns the parent directory of the IFSJavaFile. The parent directory is everything in
the path name before the last occurrence of the separator
character, or null if the separator character does not appear in
the path name.
The following example demonstrates the use of this method:
In this example, parentPath would equal "\test".
String path = "\\test\\path";
IFSJavaFile file = new IFSJavaFile(new AS400("enterprise"), path);
String parentPath = file.getParent();
- Returns:
- The parent directory if one exists;
null
otherwise.
- Overrides:
- getParent in class File
- See Also:
- getPath
getPath
public String getPath()
- Returns the path name of the IFSJavaFile.
The following example demonstrates the use of this method:
In this example, thePath would equal "\test\path" the same value as path.
String path = "\\test\\path";
IFSJavaFile file = new IFSJavaFile(new AS400("enterprise"), path);
String thePath = file.getPath();
- Returns:
- The file path name.
- Overrides:
- getPath in class File
getSystem
public AS400 getSystem()
- Returns the system that this object references.
- Returns:
- The system object.
hashCode
public int hashCode()
- Computes a hashcode for this object.
- Returns:
- A hash code value for this object.
- Overrides:
- hashCode in class File
isAbsolute
public boolean isAbsolute()
- Indicates if the path name of this IFSJavaFile is an
absolute path name.
- Returns:
-
true
if the path name specification is absolute; false
otherwise.
- Overrides:
- isAbsolute in class File
isDirectory
public boolean isDirectory()
- Indicates if the IFSJavaFile is a directory.
- Returns:
-
true
if the IFSJavaFile exists and is a directory; false
otherwise.
- Overrides:
- isDirectory in class File
isFile
public boolean isFile()
- Indicates if the IFSJavaFile is a "normal" file.
A file is "normal" if it is not a directory or a container of other objects.
- Returns:
-
true
if the specified file exists and is a "normal" file; false
otherwise.
- Overrides:
- isFile in class File
lastModified
public long lastModified()
- Indicates the time that the IFSJavaFile was last modified.
- Returns:
- The time (measured in milliseconds since
01/01/1970 00:00:00 GMT) that the IFSJavaFile was
last modified, or
0
if it does not exist.
- Overrides:
- lastModified in class File
length
public long length()
- Indicates the length of this IFSJavaFile.
- Returns:
- The length, in bytes, of the IFSJavaFile,
or
0
if it does not exist.
- Overrides:
- length in class File
list
public String[] list()
- Lists the files in this IFSJavaFile directory.
- Returns:
- An array of object names in the directory.
This list does not include the current directory
or the parent directory. If this IFSJavaFile is not
a directory, null is returned.
If this IFSJavaFile is an empty directory,
an empty string array is returned.
- Overrides:
- list in class File
list
public String[] list(FilenameFilter filter)
- Lists the files in this IFSJavaFile directory that satisfy filter.
- Parameters:
- filter - The file name filter.
- Returns:
- An array of object names in the directory that satisfy
the file name filter. This list does not include the current
directory or the parent directory. If this IFSJavaFile is not
a directory, null is returned. If this IFSJavaFile is an empty
directory, or the file name filter does
not match any files, an empty string array is returned.
The IFSJavaFile object passed to the file name filter object have cached
file attribute information. Maintaining references to these
IFSJavaFile objects after the list operation increases the
chances that their file attribute information will not be valid.
The following example demonstrates the use of this method:
class AcceptClass implements java.io.FilenameFilter
{
public boolean accept(java.io.File dir, java.lang.String name)
{
if (name.startsWith ("IFS"))
return true;
return false;
}
}
IFSJavaFile file = new IFSJavaFile(new AS400("enterprise"), path);
AcceptClass ac = new AcceptClass();
file.list (ac);
- Overrides:
- list in class File
list
public String[] list(IFSFileFilter filter)
- Lists the files in the IFSJavaFile directory that satisfy file name filter.
- Parameters:
- filter - The file name filter.
- Returns:
- An array of object names in the directory that
satisfy the file name filter. This list does not include the current
directory or the parent directory.
If this IFSJavaFile is not a directory, null is
returned. If this IFSJavaFile is an empty directory, or
the file name filter does not match any files, an empty string array
is returned. The IFSFile object passed to the file name filter object
have cached file attribute information. Maintaining
references to these IFSFile objects after the list operation
increases the chances that their file attribute information
will not be valid.
The following example demonstrates the use of this method:
class AcceptClass implements IFSFileFilter
{
public boolean accept(IFSFile file)
{
if (file.getName().startsWith ("IFS"))
return true;
return false;
}
}
IFSJavaFile file = new IFSJavaFile(new AS400("enterprise"), path);
AcceptClass ac = new AcceptClass();
file.list (ac);
list
public String[] list(IFSFileFilter filter,
String pattern)
- Lists the files in this IFSJavaFile directory that satisfy filter and pattern.
Note:
If the file does not match pattern, it will not be processed by filter.
- Parameters:
- filter - The file name filter.
- pattern - The pattern that all filenames must match. Acceptable characters are
wildcards (* - matches multiple characters) and question marks (? - matches
one character). Pattern must not be null.
- Returns:
- An array of object names in the directory that satisfy the file name filter
and pattern. This list does not include the current directory or the parent
directory. If this IFSJavaFile is not a directory, null is returned. If this
IFSJavaFile is an empty directory, or the file name filter or pattern does not
match any files, an empty string array is returned. The IFSFile object passed
to the file name filter object have cached file attribute information.
Maintaining references to these IFSFile objects after the list operation
increases the chances that their file attribute information will not be valid.
list
public String[] list(String pattern)
- Lists the files in this IFSJavaFile directory that match pattern.
- Parameters:
- pattern - The pattern that all filenames must match.
Acceptable characters are wildcards (* - matches
multiple characters) and question marks (? - matches
one character).
- Returns:
- An array of object names in the directory that match
the pattern. This list does not include the current
directory or the parent directory. If this IFSJavaFile
is not a directory, null is returned. If this IFSJavaFile
is an empty directory, or the pattern does not match any
files, an empty string array is returned.
mkdir
public boolean mkdir()
- Creates a directory whose path name
is specified by this IFSJavaFile.
- Returns:
-
true
if the directory could be created;
false
otherwise.
- Overrides:
- mkdir in class File
mkdirs
public boolean mkdirs()
- Creates a directory whose path name is
specified by this IFSJavaFile, including any necessary
parent directories.
- Returns:
-
true
if the directory (or directories) could be
created; false
otherwise.
- Overrides:
- mkdirs in class File
renameTo
public boolean renameTo(IFSJavaFile dest)
- Renames the IFSJavaFile to have the path name of dest.
Wildcards are not permitted in this file name.
- Parameters:
- dest - The new filename.
- Returns:
-
true
if the renaming succeeds;
false
otherwise.
setPath
public boolean setPath(String path)
- Sets the path for this IFSJavaFile.
- Parameters:
- path - The absolute file path.
- Returns:
-
true
if the path was set;
false
otherwise.
setSystem
public boolean setSystem(AS400 system)
- Sets the system.
- Parameters:
- system - The AS/400 system object.
- Returns:
-
true
if the system was set;
false
otherwise.
toString
public String toString()
- Returns a string representation of this object.
- Returns:
- A string giving the path name of this object.
- Overrides:
- toString in class File
All Packages Class Hierarchy This Package Previous Next Index