Serializable
, Comparable<File>
public class IFSJavaFile extends File implements Serializable
When should IFSJavaFile be used?
IFSFile
is more useful. IFSFile is written to
handle more of the specific IBM i 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 IBM i system or the local client.
int location = ON_THE_SERVER; // on the IBM i system java.io.File file = null; java.io.OutputStream os = null;
if (location == ON_THE_SERVER) 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_SERVER) 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 FormpathSeparator, pathSeparatorChar, separator, separatorChar
Constructor | Description |
---|---|
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.
|
Modifier and Type | Method | Description |
---|---|---|
boolean |
canExecute() |
Tests whether the application can execute the file denoted by this abstract pathname.
|
boolean |
canRead() |
Indicates if the program can read from the file denoted by this abstract pathname.
|
boolean |
canWrite() |
Indicates if the program can write to the file denoted by this abstract pathname.
|
int |
compareTo(IFSFile file) |
Compares the path of IFSJavaFile with a
IFSFile 's path. |
int |
compareTo(IFSJavaFile file) |
Compares the paths of two IFSJavaFiles.
|
int |
compareTo(File file) |
Compares the path of IFSJavaFile with a
File 's path. |
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.
|
long |
getFreeSpace() |
Returns the number of unallocated bytes in the partition named by this abstract path name.
|
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.
|
long |
getTotalSpace() |
Returns the size of the partition named by this abstract pathname.
|
long |
getUsableSpace() |
Returns the number of bytes available to this virtual machine on the partition named by this abstract pathname.
|
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.
|
String[] |
list() |
Lists the files in this IFSJavaFile directory.
|
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(FilenameFilter filter) |
Lists the files in this IFSJavaFile directory that satisfy filter.
|
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(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(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(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 IBM i 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(IFSJavaFile dest) |
Renames the IFSJavaFile to have the path name of dest.
|
boolean |
renameTo(File dest) |
Renames the IFSJavaFile to have the path name of dest.
|
boolean |
setExecutable(boolean executable) |
A convenience method to set the owner's execute permission for this abstract pathname.
|
boolean |
setExecutable(boolean executable,
boolean ownerOnly) |
Sets the owner's or everybody's execute permission for this abstract pathname.
|
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 |
setReadable(boolean readable) |
A convenience method to set the owner's read permission for this abstract pathname.
|
boolean |
setReadable(boolean readable,
boolean ownerOnly) |
Sets the owner's or everybody's read permission for this abstract pathname.
|
boolean |
setReadOnly() |
Marks the file named by this IFSJavaFile object so that only
read operations are allowed.
|
boolean |
setSystem(AS400 system) |
Sets the system.
|
boolean |
setWritable(boolean writable) |
A convenience method to set the owner's write permission for this abstract pathname.
|
boolean |
setWritable(boolean writable,
boolean ownerOnly) |
Sets the owner's or everybody's write permission for this abstract pathname.
|
String |
toString() |
Returns a string representation of this object.
|
URL |
toURL() |
Converts the abstract path name into a
file: URL. |
createTempFile, createTempFile, deleteOnExit, toPath, toURI
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.public boolean canExecute() throws SecurityException
canExecute
in class File
SecurityException
- If an unanticipated security error occurs.public boolean canRead() throws SecurityException
canRead
in class File
SecurityException
- If an unanticipated security error occurs.public boolean canWrite() throws SecurityException
canWrite
in class File
SecurityException
- If an unanticipated security error occurs.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.
compareTo
in interface Comparable<File>
compareTo
in class File
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
createNewFile
in class File
IOException
- If an I/O error occurs while communicating with the IBM i system.public boolean delete() throws SecurityException
delete
in class File
true
if the file is successfully deleted;
false
otherwise.SecurityException
- If the user is denied access to the file.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.public boolean exists() throws SecurityException
exists
in class File
true
if the file specified by this object
exists; false
otherwise.SecurityException
- If the user is denied read access to the file.SecurityException
- If the user is denied access to the file.public File getAbsoluteFile()
getAbsoluteFile
in class File
getAbsolutePath()
public String getAbsolutePath()
getAbsolutePath
in class File
isAbsolute()
public File getCanonicalFile() throws IOException
getCanonicalFile
in class File
IOException
- If an I/O error occurs while communicating with the IBM i system.getCanonicalPath()
public String getCanonicalPath() throws IOException
getCanonicalPath
in class File
IOException
- If an I/O error occurs while communicating with the IBM i system.public long getFreeSpace() throws SecurityException
The returned number of unallocated bytes is a hint, but not a guarantee, that it is possible to use most or any of these bytes. The number of unallocated bytes is most likely to be accurate immediately after this call. It is likely to be made inaccurate by any external I/O operations including those made on the system outside of this virtual machine. This method makes no guarantee that write operations to this file system will succeed.
getFreeSpace
in class File
SecurityException
- If the user is denied access to the file.public long getTotalSpace() throws SecurityException
getTotalSpace
in class File
SecurityException
- If the user is denied access to the file.public long getUsableSpace() throws SecurityException
The returned number of available bytes is a hint, but not a guarantee, that it is possible to use most or any of these bytes. The number of unallocated bytes is most likely to be accurate immediately after this call. It is likely to be made inaccurate by any external I/O operations including those made on the system outside of this virtual machine. This method makes no guarantee that write operations to this file system will succeed.
Note: If the user profile has a "maximum storage allowed" setting of *NOMAX, then getUsableSpace() returns the same value as getFreeSpace()
.
getUsableSpace
in class File
SecurityException
- If the user is denied access to the file.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();
getParent
in class File
getParentFile()
public File getParentFile()
getParentFile
in class File
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
- If an error occurs while communicating with the system.public AS400 getSystem()
public int hashCode()
public boolean isAbsolute()
isAbsolute
in class File
true
if the path name specification is absolute; false
otherwise.public boolean isDirectory() throws SecurityException
isDirectory
in class File
true
if the IFSJavaFile exists and is a directory; false
otherwise.SecurityException
- If the user is denied access to the file.public boolean isFile() throws SecurityException
isFile
in class File
true
if the specified file exists and is a "normal" file; false
otherwise.SecurityException
- If the user is denied access to the file.public boolean isHidden() throws SecurityException
isHidden
in class File
true
if the file is hidden; false
otherwise.SecurityException
- If the user is denied access to the file.public long lastModified() throws SecurityException
lastModified
in class File
0
if it does not exist.SecurityException
- If the user is denied access to the file.public long length() throws SecurityException
length
in class File
0
((IFSJavaFile) if it does not exist.SecurityException
- If the user is denied access to the file.public String[] list() throws SecurityException
list
in class File
SecurityException
- If the user is denied access to the file.listFiles()
public String[] list(FilenameFilter filter) throws SecurityException
list
in class File
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);
SecurityException
- If the user is denied access to the file.listFiles(FilenameFilter)
public String[] list(IFSFileFilter filter) throws SecurityException
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);
SecurityException
- If the user is denied access to the file.listFiles(IFSFileFilter)
public String[] list(IFSFileFilter filter, String pattern) throws SecurityException
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.SecurityException
- If the user is denied access to the file.listFiles(IFSFileFilter,String)
public String[] list(String pattern) throws SecurityException
pattern
- The pattern that all filenames must match.
Acceptable characters are wildcards (* - matches
multiple characters) and question marks (? - matches
one character).SecurityException
- If the user is denied access to the file.listFiles(String)
public File[] listFiles() throws SecurityException
listFiles
in class File
SecurityException
- If the user is denied access to the file.list()
public File[] listFiles(FilenameFilter filter) throws SecurityException
listFiles
in class File
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);
SecurityException
- If the user is denied access to the file.list(FilenameFilter)
public File[] listFiles(FileFilter filter) throws SecurityException
listFiles
in class File
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);
SecurityException
- If the user is denied access to the file.public File[] listFiles(IFSFileFilter filter) throws SecurityException
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);
SecurityException
- If the user is denied access to the file.list(IFSFileFilter)
public File[] listFiles(IFSFileFilter filter, String pattern) throws SecurityException
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.SecurityException
- If the user is denied access to the file.list(IFSFileFilter,String)
public File[] listFiles(String pattern) throws SecurityException
pattern
- The pattern that all filenames must match.
Acceptable characters are wildcards (* - matches
multiple characters) and question marks (? - matches
one character).SecurityException
- If the user is denied access to the file.list(String)
public static File[] listRoots()
public boolean mkdir() throws SecurityException
mkdir
in class File
true
if the directory could be created;
false
otherwise.SecurityException
- If the user is denied access to the file.public boolean mkdirs() throws SecurityException
mkdirs
in class File
true
if the directory (or directories) could be
created; false
otherwise.SecurityException
- If the user is denied access to the file.public boolean renameTo(IFSJavaFile dest) throws SecurityException
dest
- The new filename.true
if the renaming succeeds;
false
otherwise.SecurityException
- If the user is denied access to the file.public boolean renameTo(File dest) throws SecurityException
renameTo
in class File
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.SecurityException
- If the user is denied access to the file.public boolean setLastModified(long time) throws SecurityException
setLastModified
in class File
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.SecurityException
- If the user is denied access to the file.public boolean setLength(int length) throws SecurityException
length
- The new length, in bytes.SecurityException
- If the user is denied access to the file.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
IOException
- If an error occurs while communicating with the system.ConnectionDroppedException
- If the connection is dropped unexpectedly.ExtendedIOException
- If an error occurs while communicating with the system.ServerStartupException
- If the host server cannot be started.public boolean setReadOnly() throws SecurityException
setReadOnly
in class File
true
if the read only attribute is set; false
otherwise.SecurityException
- If the user is denied access to the file.public boolean setSystem(AS400 system)
system
- The system object.true
if the system was set;
false
otherwise.public boolean setExecutable(boolean executable) throws SecurityException
An invocation of this method of the form file.setExcutable(arg) behaves in exactly the same way as the invocation file.setExecutable(arg, true)
setExecutable
in class File
executable
- If true, sets the access permission to allow execute operations; if false, to disallow execute operations.SecurityException
- If the user is denied access to the file.public boolean setExecutable(boolean executable, boolean ownerOnly) throws SecurityException
setExecutable
in class File
executable
- If true, sets the access permission to allow execute operations; if false, to disallow execute operations.ownerOnly
- If true, the execute permission applies only to the owner's execute permission; otherwise, it applies to everybody.SecurityException
- If the user is denied access to the file.public boolean setReadable(boolean readable) throws SecurityException
An invocation of this method of the form file.setReadable(arg) behaves in exactly the same way as the invocation file.setReadable(arg, true)
setReadable
in class File
readable
- If true, sets the access permission to allow read operations; if false, to disallow read operations.SecurityException
- If the user is denied access to the file.public boolean setReadable(boolean readable, boolean ownerOnly) throws SecurityException
setReadable
in class File
readable
- If true, sets the access permission to allow read operations; if false, to disallow read operations.ownerOnly
- If true, the read permission applies only to the owner's read permission; otherwise, it applies to everybody.SecurityException
- If the user is denied access to the file.public boolean setWritable(boolean writable) throws SecurityException
An invocation of this method of the form file.setWritable(arg) behaves in exactly the same way as the invocation file.setWritable(arg, true)
setWritable
in class File
writable
- If true, sets the access permission to allow write operations; if false to disallow write operationsSecurityException
- If the user is denied access to the file.public boolean setWritable(boolean writable, boolean ownerOnly) throws SecurityException
setWritable
in class File
writable
- If true, sets the access permission to allow write operations; if false, to disallow write operations.ownerOnly
- If true, the write permission applies only to the owner's write permission; otherwise, it applies to everybody.SecurityException
- If the user is denied access to the file.public String toString()
public URL toURL() throws MalformedURLException
file:
URL.
The IBM i file/directory will be accessed and if it is a directory the
resulting URL will end with the IBM i 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.toURL
in class File
MalformedURLException
- If the URL cannot be formed.Copyright © 2024. All rights reserved.