|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.io.File | +--com.ibm.as400.access.IFSJavaFile
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 java.io.File class.
When should IFSJavaFile be used?
Notes:
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); }
IFSFile
,
IFSFileInputStream
,
IFSFileOutputStream
, Serialized FormFields inherited from class java.io.File |
pathSeparator,
pathSeparatorChar,
separator,
separatorChar |
Constructor Summary | |
IFSJavaFile()
Constructs an IFSJavaFile object. |
|
IFSJavaFile(AS400 system,
IFSJavaFile directory,
java.lang.String name)
Constructs an IFSJavaFile object. |
|
IFSJavaFile(AS400 system,
java.lang.String path)
Constructs an IFSJavaFile object. |
|
IFSJavaFile(AS400 system,
java.lang.String path,
java.lang.String name)
Constructs an IFSJavaFile object. |
|
IFSJavaFile(IFSJavaFile directory,
java.lang.String name)
Constructs an IFSJavaFile object. |
Method Summary | |
boolean |
canRead()
Indicates if the program can read from the IFSJavaFile. |
boolean |
canWrite()
Indicates if the program can write to the IFSJavaFile. |
int |
compareTo(IFSJavaFile file)
Compares the paths of two IFSJavaFiles. |
int |
compareTo(java.lang.Object obj)
Compares the path of IFSJavaFile with Object's path. |
boolean |
createNewFile()
Atomically create a new, empty file. |
boolean |
delete()
Deletes the IFSJavaFile. |
boolean |
equals(java.lang.Object obj)
Compares this IFSJavaFile against the specified object. |
boolean |
exists()
Indicates if the IFSJavaFile exists. |
java.io.File |
getAbsoluteFile()
Returns An IFSJavaFile object based on the absolute path name of the current object. |
java.lang.String |
getAbsolutePath()
Returns the absolute path name of the IFSJavaFile. |
java.io.File |
getCanonicalFile()
Returns An IFSJavaFile object based on the canonical path name of the current object. |
java.lang.String |
getCanonicalPath()
Returns the path name in canonical form of IFSJavaFile path. |
java.lang.String |
getName()
Returns the name of the IFSJavaFile. |
java.lang.String |
getParent()
Returns the parent directory of the IFSJavaFile. |
java.io.File |
getParentFile()
Returns an IFSJavaFile object that represents the parent of the current object. |
java.lang.String |
getPath()
Returns the path name of the IFSJavaFile. |
AS400 |
getSystem()
Returns the system that this object references. |
int |
hashCode()
Computes a hashcode for this object. |
boolean |
isAbsolute()
Indicates if the path name of this IFSJavaFile is an absolute path name. |
boolean |
isDirectory()
Indicates if the IFSJavaFile is a directory. |
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. |
boolean |
isHidden()
Indicates if the IFSJavaFile is hidden. |
long |
lastModified()
Indicates the time that the IFSJavaFile was last modified. |
long |
length()
Indicates the length of this IFSJavaFile. |
java.lang.String[] |
list()
Lists the files in this IFSJavaFile directory. |
java.lang.String[] |
list(java.io.FilenameFilter filter)
Lists the files in this IFSJavaFile directory that satisfy filter. |
java.lang.String[] |
list(IFSFileFilter filter)
Lists the files in the IFSJavaFile directory that satisfy file name filter. |
java.lang.String[] |
list(IFSFileFilter filter,
java.lang.String pattern)
Lists the files in this IFSJavaFile directory that satisfy filter and pattern. |
java.lang.String[] |
list(java.lang.String pattern)
Lists the files in this IFSJavaFile directory that match pattern. |
java.io.File[] |
listFiles()
Lists the files in this IFSJavaFile directory. |
java.io.File[] |
listFiles(java.io.FilenameFilter filter)
Lists the files in this IFSJavaFile directory that satisfy filter. |
java.io.File[] |
listFiles(IFSFileFilter filter)
Lists the files in the IFSJavaFile directory that satisfy file name filter. |
java.io.File[] |
listFiles(IFSFileFilter filter,
java.lang.String pattern)
Lists the files in this IFSJavaFile directory that satisfy filter and pattern. |
java.io.File[] |
listFiles(java.lang.String pattern)
Lists the files in this IFSJavaFile directory that match pattern. |
static java.io.File[] |
listRoots()
Lists the file system roots for the integrated file system of the AS/400. |
boolean |
mkdir()
Creates a directory whose path name is specified by this IFSJavaFile. |
boolean |
mkdirs()
Creates a directory whose path name is specified by this IFSJavaFile, including any necessary parent directories. |
boolean |
renameTo(IFSJavaFile dest)
Renames the IFSJavaFile to have the path name of dest. |
boolean |
setLastModified(long time)
Set the last modified time of the file named by this IFSJavaFile object. |
boolean |
setPath(java.lang.String path)
Sets the path for this IFSJavaFile. |
boolean |
setReadOnly()
Marks the file named by this IFSJavaFile object so that only read operations are allowed. |
boolean |
setSystem(AS400 system)
Sets the system. |
java.lang.String |
toString()
Returns a string representation of this object. |
java.net.URL |
toURL()
Converts the abstract path name into a file: URL. |
Methods inherited from class java.io.File |
compareTo,
createTempFile,
createTempFile,
deleteOnExit,
listFiles,
renameTo |
Methods inherited from class java.lang.Object |
clone,
finalize,
getClass,
notify,
notifyAll,
wait,
wait,
wait |
Constructor Detail |
public IFSJavaFile()
public IFSJavaFile(AS400 system, java.lang.String path)
IFSJavaFile
on system that has a path name of path.system
- The AS400 that contains the IFSJavaFile.path
- The file path name where the IFSJavaFile is or will be stored.public IFSJavaFile(AS400 system, java.lang.String path, java.lang.String name)
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.public IFSJavaFile(IFSJavaFile directory, java.lang.String name)
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:
directory
- The directory where the IFSJavaFile is or will be stored.name
- The name of the IFSJavaFile object.getPath()
public IFSJavaFile(AS400 system, IFSJavaFile directory, java.lang.String name)
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.getPath()
Method Detail |
public boolean canRead()
true
if the object exists and is readable; false
otherwise.public boolean canWrite()
true
if the object exists and is writeable; false
otherwise.public int compareTo(IFSJavaFile file)
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.
file
- The IFSJavaFile
to be compared.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.public int compareTo(java.lang.Object obj)
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.
obj
- The Object
to be compared.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.public boolean createNewFile() throws java.io.IOException
public boolean delete()
true
if the file is successfully deleted;
false
otherwise.public boolean equals(java.lang.Object obj)
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,
and system names of the objects are equal.obj
- The object to compare with.true
if the objects are the same;
false
otherwise.public boolean exists()
true
if the file specified by this object
exists; false
otherwise.public java.io.File getAbsoluteFile()
getAbsolutePath()
public java.lang.String getAbsolutePath()
isAbsolute()
public java.io.File getCanonicalFile() throws java.io.IOException
getCanonicalPath()
public java.lang.String getCanonicalPath() throws java.io.IOException
public java.lang.String getName()
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();
IFSJavaFile
.public java.lang.String getParent()
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();
null
otherwise.getPath()
public java.io.File getParentFile()
null
otherwise.getParent()
public java.lang.String getPath()
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();
public AS400 getSystem()
public int hashCode()
public boolean isAbsolute()
true
if the path name specification is absolute; false
otherwise.public boolean isDirectory()
true
if the IFSJavaFile exists and is a directory; false
otherwise.public boolean isFile()
true
if the specified file exists and is a "normal" file; false
otherwise.public boolean isHidden()
true
if the file is hidden; false
otherwise.public long lastModified()
0
if it does not exist.public long length()
0
if it does not exist.public java.lang.String[] list()
public java.lang.String[] list(java.io.FilenameFilter filter)
filter
- The file name filter.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);
public java.lang.String[] list(IFSFileFilter filter)
filter
- The file name filter.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);
public java.lang.String[] list(IFSFileFilter filter, java.lang.String pattern)
Note:
If the file does not match pattern, it will not be processed by filter.
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.public java.lang.String[] list(java.lang.String pattern)
pattern
- The pattern that all filenames must match.
Acceptable characters are wildcards (* - matches
multiple characters) and question marks (? - matches
one character).public java.io.File[] listFiles()
public java.io.File[] listFiles(java.io.FilenameFilter filter)
filter
- The file name filter.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.listFiles (ac);
public java.io.File[] listFiles(IFSFileFilter filter)
filter
- The file name filter.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.listFiles (ac);
public java.io.File[] listFiles(IFSFileFilter filter, java.lang.String pattern)
Note:
If the file does not match pattern, it will not be processed by filter.
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.public java.io.File[] listFiles(java.lang.String pattern)
pattern
- The pattern that all filenames must match.
Acceptable characters are wildcards (* - matches
multiple characters) and question marks (? - matches
one character).public static java.io.File[] listRoots()
public boolean mkdir()
true
if the directory could be created;
false
otherwise.public boolean mkdirs()
true
if the directory (or directories) could be
created; false
otherwise.public boolean renameTo(IFSJavaFile dest)
dest
- The new filename.true
if the renaming succeeds;
false
otherwise.public boolean setLastModified(long time)
time
- The new last modified time, measured in milliseconds since
00:00:00 GMT, January 1, 1970.true
if the time is set; false
otherwise.public boolean setPath(java.lang.String path)
path
- The absolute file path.true
if the path was set;
false
otherwise.public boolean setReadOnly()
true
if the read only attribute is set; false
otherwise.public boolean setSystem(AS400 system)
system
- The AS/400 system object.true
if the system was set;
false
otherwise.public java.lang.String toString()
public java.net.URL toURL() throws java.net.MalformedURLException
file:
URL.
The AS/400 file/directory will be accessed and if it is a directory the
resulting URL will end with the AS/400 separator character
(forward slash). The server name will be obtained from
the AS400 object. If the path name or AS400 object has
not been set, a NullPointerException will be thrown.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |