er.extensions.foundation
Class ERXFile
java.lang.Object
java.io.File
er.extensions.foundation.ERXFile
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Comparable<java.io.File>
public class ERXFile
- extends java.io.File
Fixes some inconsistencies with java.io.File on MacOS X HFS+ filesystem and
should be used as a replacement.
For example, the following code will not work as expected:
File f = new File("/tmp/FilenameWithSpecialCharacterÄÖÜ");
f.createNewFile();
File tmp = new File("/tmp");
File[] contents = tmp.listFiles();
for (int i = 0; i < contents.length; i++) {
if (contents[i].getName().equals("FilenameWithSpecialCharacterÄÖÜ")) {
System.out.println("found it!");
}
}
One would expect that the comparison
contents[i].getName().equals("FilenameWithSpecialCharacterÄÖÜ")
would result in true
. This is not the case, at least not on HFS+
This subclass fixes this and should be used instead of java.io.File.
Actually, the code above _does_ work (WO 5.4.3, Mac OS X 10.5.8, java 1.5.0_22),
but what else does this do? -rrk
- See Also:
- Serialized Form
- Author:
- David Teran
Fields inherited from class java.io.File |
pathSeparator, pathSeparatorChar, separator, separatorChar |
Constructor Summary |
ERXFile(java.io.File parent,
java.lang.String child)
Creates a new File instance from a parent abstract pathname and a child pathname string. |
ERXFile(java.lang.String pathname)
Creates a new File instance by converting the given pathname string into an abstract pathname. |
ERXFile(java.lang.String parent,
java.lang.String child)
Creates a new File instance from a parent pathname string and a child pathname string. |
ERXFile(java.net.URI uri)
Creates a new File instance by converting the given file: URI into an abstract pathname. |
Methods inherited from class java.io.File |
canExecute, canRead, canWrite, compareTo, createNewFile, createTempFile, createTempFile, delete, deleteOnExit, equals, exists, getCanonicalPath, getFreeSpace, getParent, getPath, getTotalSpace, getUsableSpace, hashCode, isAbsolute, isDirectory, isFile, isHidden, lastModified, length, listRoots, mkdir, mkdirs, renameTo, setExecutable, setExecutable, setLastModified, setReadable, setReadable, setReadOnly, setWritable, setWritable, toURI, toURL |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
ERXFile
public ERXFile(java.io.File parent,
java.lang.String child)
- Creates a new File instance from a parent abstract pathname and a child pathname string.
If parent is null then the new File instance is created as if by invoking the single-argument
File constructor on the given child pathname string.
Otherwise the parent abstract pathname is taken to denote a directory, and the child pathname
string is taken to denote either a directory or a file. If the child pathname string is absolute
then it is converted into a relative pathname in a system-dependent way. If parent is the empty
abstract pathname then the new File instance is created by converting child into an abstract
pathname and resolving the result against a system-dependent default directory. Otherwise each
pathname string is converted into an abstract pathname and the child abstract pathname is
resolved against the parent.
- Parameters:
parent
- - The parent abstract pathnamechild
- - The child pathname string
- Throws:
java.lang.NullPointerException
- - If child is null
ERXFile
public ERXFile(java.lang.String pathname)
- Creates a new File instance by converting the given pathname string into an abstract pathname.
If the given string is the empty string, then the result is the empty abstract pathname.
- Parameters:
pathname
- - A pathname string
- Throws:
java.lang.NullPointerException
- - If the pathname argument is null
ERXFile
public ERXFile(java.lang.String parent,
java.lang.String child)
- Creates a new File instance from a parent pathname string and a child pathname string.
If parent is null then the new File instance is created as if by invoking the single-argument File
constructor on the given child pathname string.
Otherwise the parent pathname string is taken to denote a directory, and the child pathname string is
taken to denote either a directory or a file. If the child pathname string is absolute then it is
converted into a relative pathname in a system-dependent way. If parent is the empty string then the
new File instance is created by converting child into an abstract pathname and resolving the result
against a system-dependent default directory. Otherwise each pathname string is converted into an
abstract pathname and the child abstract pathname is resolved against the parent.
- Parameters:
parent
- - The parent pathname stringchild
- - The child pathname string
- Throws:
java.lang.NullPointerException
- - If child is null
ERXFile
public ERXFile(java.net.URI uri)
- Creates a new File instance by converting the given file: URI into an abstract pathname.
The exact form of a file: URI is system-dependent, hence the transformation performed by this
constructor is also system-dependent.
For a given abstract pathname
f
it is guaranteed that
new File(f.toURI()).equals(f.getAbsoluteFile())
so long as the original abstract pathname, the URI, and the new abstract pathname are all
created in (possibly different invocations of) the same Java virtual machine. This relationship
typically does not hold, however, when a file: URI that is created in a virtual machine on one
operating system is converted into an abstract pathname in a virtual machine on a different
operating system.
- Parameters:
uri
- - An absolute, hierarchical URI with a scheme equal to "file", a non-empty path component,
and undefined authority, query, and fragment components
- Throws:
java.lang.NullPointerException
- - If uri is null
java.lang.IllegalArgumentException
- - If the preconditions on the parameter do not hold- Since:
- 1.4
getAbsolutePath
public java.lang.String getAbsolutePath()
- Overrides:
getAbsolutePath
in class java.io.File
getName
public java.lang.String getName()
- Overrides:
getName
in class java.io.File
list
public java.lang.String[] list()
- Overrides:
list
in class java.io.File
list
public java.lang.String[] list(java.io.FilenameFilter arg0)
- Overrides:
list
in class java.io.File
listFiles
public java.io.File[] listFiles()
- Overrides:
listFiles
in class java.io.File
listFiles
public java.io.File[] listFiles(java.io.FileFilter arg0)
- Overrides:
listFiles
in class java.io.File
listFiles
public java.io.File[] listFiles(java.io.FilenameFilter arg0)
- Overrides:
listFiles
in class java.io.File
getAbsoluteFile
public java.io.File getAbsoluteFile()
- Overrides:
getAbsoluteFile
in class java.io.File
getCanonicalFile
public java.io.File getCanonicalFile()
throws java.io.IOException
- Overrides:
getCanonicalFile
in class java.io.File
- Throws:
java.io.IOException
getParentFile
public java.io.File getParentFile()
- Overrides:
getParentFile
in class java.io.File
toString
public java.lang.String toString()
- Overrides:
toString
in class java.io.File
normalizedPath
public static java.lang.String normalizedPath(java.lang.String name)
Copyright © 2002 – 2007 Project Wonder.