|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.File
com.ibm.as400.access.IFSJavaFile
The IFSJavaFile class represents a file in the
integrated file system of an i5/OS system.
IFSJavaFile extends the java.io.File class and allows programs
to be written for the java.io.File interface and still access
the i5/OS integrated file system.
IFSFile should be considered as an alternate to java.io.File class.
When should IFSJavaFile be used?
IFSFile
is more useful. IFSFile is written to
handle more of the specific i5/OS integrated file system details.
Notes:
IFSFileInputStream
and
IFSFileOutputStream
.
It does not support java.io.FileInputStream
and java.io.FileOutputStream.
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 i5/OS system 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 FormField Summary |
---|
Fields inherited from class java.io.File |
---|
pathSeparator, pathSeparatorChar, separator, separatorChar |
Constructor Summary | |
---|---|
IFSJavaFile()
Creates a default IFSJavaFile instance. |
|
IFSJavaFile(AS400 system,
IFSJavaFile directory,
String name)
Creates a new IFSJavaFile instance for the specified system, from a parent abstract pathname and a child pathname string. |
|
IFSJavaFile(AS400 system,
String path)
Creates a new IFSJavaFile instance for the specified system, using a file pathname string. |
|
IFSJavaFile(AS400 system,
String path,
String name)
Creates a new IFSJavaFile instance for the specified system, from a parent pathname string and a child pathname string. |
|
IFSJavaFile(IFSFile file)
Creates a new IFSJavaFile instance from an IFSFile object. |
|
IFSJavaFile(IFSJavaFile directory,
String name)
Creates a new IFSJavaFile instance from a parent abstract pathname and a child pathname string. |
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(File file)
Compares the path of IFSJavaFile with a File 's path.
|
int |
compareTo(IFSFile file)
Compares the path of IFSJavaFile with a IFSFile 's path.
|
int |
compareTo(IFSJavaFile file)
Compares the paths of two IFSJavaFiles. |
boolean |
createNewFile()
Atomically create a new, empty file. |
boolean |
delete()
Deletes the IFSJavaFile. |
boolean |
equals(Object obj)
Compares this IFSJavaFile against the specified object. |
boolean |
exists()
Indicates if the IFSJavaFile exists. |
File |
getAbsoluteFile()
Returns An IFSJavaFile object based on the absolute path name of the current object. |
String |
getAbsolutePath()
Returns the absolute path name of the IFSJavaFile. |
File |
getCanonicalFile()
Returns An IFSJavaFile object based on the canonical path name of the current object. |
String |
getCanonicalPath()
Returns the path name in canonical form of IFSJavaFile path. |
String |
getName()
Returns the name of the IFSJavaFile. |
String |
getParent()
Returns the parent directory of the IFSJavaFile. |
File |
getParentFile()
Returns an IFSJavaFile object that represents the parent of the current object. |
String |
getPath()
Returns the path name of the IFSJavaFile. |
int |
getPatternMatching()
Returns the pattern-matching behavior used when files are listed by any of the list() or listFiles() methods. |
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. |
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. |
String[] |
list()
Lists the files in this IFSJavaFile directory. |
String[] |
list(FilenameFilter filter)
Lists the files in this IFSJavaFile directory that satisfy filter. |
String[] |
list(IFSFileFilter filter)
Lists the files in the IFSJavaFile directory that satisfy file name filter. |
String[] |
list(IFSFileFilter filter,
String pattern)
Lists the files in this IFSJavaFile directory that satisfy filter and pattern. |
String[] |
list(String pattern)
Lists the files in this IFSJavaFile directory that match pattern. |
File[] |
listFiles()
Lists the files in this IFSJavaFile directory. |
File[] |
listFiles(FileFilter filter)
Lists the files in this IFSJavaFile directory that satisfy filter. |
File[] |
listFiles(FilenameFilter filter)
Lists the files in this IFSJavaFile directory that satisfy filter. |
File[] |
listFiles(IFSFileFilter filter)
Lists the files in the IFSJavaFile directory that satisfy file name filter. |
File[] |
listFiles(IFSFileFilter filter,
String pattern)
Lists the files in this IFSJavaFile directory that satisfy filter and pattern. |
File[] |
listFiles(String pattern)
Lists the files in this IFSJavaFile directory that match pattern. |
static File[] |
listRoots()
Lists the file system roots for the integrated file system of the i5/OS system. |
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(File dest)
Renames the IFSJavaFile to have the path name of dest. |
boolean |
renameTo(IFSJavaFile dest)
Renames the IFSJavaFile to have the path name of dest. |
boolean |
setLastModified(long time)
Sets the last modified time of the file named by this IFSJavaFile object. |
boolean |
setLength(int length)
Sets the length of the file named by this IFSJavaFile object. |
boolean |
setPath(String path)
Sets the path for this IFSJavaFile. |
void |
setPatternMatching(int patternMatching)
Sets the pattern-matching behavior used when files are listed by any of the list() or listFiles() methods. |
boolean |
setReadOnly()
Marks the file named by this IFSJavaFile object so that only read operations are allowed. |
boolean |
setSystem(AS400 system)
Sets the system. |
String |
toString()
Returns a string representation of this object. |
URL |
toURL()
Converts the abstract path name into a file: URL.
|
Methods inherited from class java.io.File |
---|
compareTo, createTempFile, createTempFile, deleteOnExit, toURI |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public IFSJavaFile()
public IFSJavaFile(AS400 system, String path)
system
- The system that contains the IFSJavaFile.path
- The file path name where the IFSJavaFile is or will be stored.public IFSJavaFile(AS400 system, String path, String name)
system
- The system 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, String name)
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.public IFSJavaFile(AS400 system, IFSJavaFile directory, String name)
system
- The system that contains the IFSJavaFile.directory
- The directory where the IFSJavaFile is or will be stored.name
- The name of the IFSJavaFile object.public IFSJavaFile(IFSFile file)
file
- An IFSFile object.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(File file)
File
's path.
Note:
The comparison is case sensitive.
file
- The File
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 int compareTo(IFSFile file)
IFSFile
's path.
Note:
The comparison is case sensitive.
file
- The IFSFile
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 IOException
IOException
- If an I/O error occurs while communicating with the i5/OS system.public boolean delete()
true
if the file is successfully deleted;
false
otherwise.public boolean equals(Object obj)
true
if and only if the argument is
not null and is an 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 File getAbsoluteFile()
getAbsolutePath()
public String getAbsolutePath()
isAbsolute()
public File getCanonicalFile() throws IOException
IOException
- If an I/O error occurs while communicating with the i5/OS system.getCanonicalPath()
public String getCanonicalPath() throws IOException
IOException
- If an I/O error occurs while communicating with the i5/OS system.public 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();
public 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();
public File getParentFile()
getParent()
public 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 int getPatternMatching() throws IOException
PATTERN_POSIX
, PATTERN_POSIX_ALL
, or PATTERN_OS2
IOException
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 String[] list()
listFiles()
public String[] list(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);
listFiles(FilenameFilter)
public 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);
listFiles(IFSFileFilter)
public String[] list(IFSFileFilter filter, 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.
listFiles(IFSFileFilter,String)
public String[] list(String pattern)
pattern
- The pattern that all filenames must match.
Acceptable characters are wildcards (* - matches
multiple characters) and question marks (? - matches
one character).
listFiles(String)
public File[] listFiles()
list()
public File[] listFiles(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);
list(FilenameFilter)
public File[] listFiles(FileFilter filter)
filter
- The file filter.
The following example demonstrates the use of this method:
class AcceptClass implements java.io.FileFilter { public boolean accept(java.io.File 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 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);
list(IFSFileFilter)
public File[] listFiles(IFSFileFilter filter, 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.
list(IFSFileFilter,String)
public File[] listFiles(String pattern)
pattern
- The pattern that all filenames must match.
Acceptable characters are wildcards (* - matches
multiple characters) and question marks (? - matches
one character).
list(String)
public static 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 renameTo(File dest)
dest
- An object specifying the new filename.
If this object is not an IFSJavaFile, the rename will fail.
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.
If -1, sets the last modified time to the current system time.
true
if the time is set; false
otherwise.public boolean setLength(int length)
length
- The new length, in bytes.
public boolean setPath(String path)
path
- The absolute file path.
true
if the path was set;
false
otherwise.public void setPatternMatching(int patternMatching) throws IOException
patternMatching
- Either PATTERN_POSIX
, PATTERN_POSIX_ALL
, or PATTERN_OS2
ConnectionDroppedException
- If the connection is dropped unexpectedly.
ExtendedIOException
- If an error occurs while communicating with the system.
InterruptedIOException
- If this thread is interrupted.
ServerStartupException
- If the host server cannot be started.
UnknownHostException
- If the system cannot be located.
IOException
public boolean setReadOnly()
true
if the read only attribute is set; false
otherwise.public boolean setSystem(AS400 system)
system
- The system object.
true
if the system was set;
false
otherwise.public String toString()
public URL toURL() throws MalformedURLException
file:
URL.
The i5/OS file/directory will be accessed and if it is a directory the
resulting URL will end with the i5/OS separator character
(forward slash). The system name will be obtained from
the AS400 object. If the path name or AS400 object has
not been set, a NullPointerException will be thrown.
MalformedURLException
- If the URL cannot be formed.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |