public class FileUtil
extends java.lang.Object
Constructor and Description |
---|
FileUtil() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
compressPath(java.lang.String path,
int maxPathLength)
Returns a compressed version of the path.
|
static void |
copyFile(java.io.File src,
java.io.File dst)
Same as
copyFile(src, dst, true)) . |
static void |
copyFile(java.io.File src,
java.io.File dst,
boolean copyLMD)
Copies a file; silently overwrites the destination if already exists.
|
static java.lang.String |
getFileExtension(java.lang.String name)
Returns the part of the name after the last dot, or if there's no dot,
null . |
static java.lang.String |
getLowerCaseFileExtension(java.lang.String name)
Same as
getFileExtension(String) , but also converts the result to lower case. |
static java.lang.String |
getRelativePath(java.io.File fromDir,
java.io.File toFileOrDir)
Reaturns the path of a file or directory relative to a directory,
in native format.
|
static boolean |
isInside(java.io.File file,
java.io.File ascendant)
Returns true if
file is inside ascendant ,
otherwise returns false. |
static boolean |
isInsideOrEquals(java.io.File file,
java.io.File ascendant)
Returns true if
file is inside ascendant or
file is the same as the ascendant , otherwise
returns false. |
static byte[] |
loadByteArray(java.io.InputStream in) |
static java.lang.String |
loadString(java.io.InputStream in,
java.lang.String charset) |
static java.lang.String |
pathPatternToPerl5Regex(java.lang.String text)
Converts UN*X style path to regular expression (originally, for Perl 5 dialect, but also works for Java's
dialect).
|
static java.lang.String |
pathToUnixStyle(java.lang.String path)
Brings the path to UNI*X style format, so that it can be handled
with path pattern handling functions.
|
static java.lang.String |
removeSlashPrefix(java.lang.String path) |
static java.io.File |
resolveRelativeUnixPath(java.io.File root,
java.io.File wd,
java.lang.String path)
Resolves relative UN*X path based on given root and working directory.
|
public static java.lang.String getRelativePath(java.io.File fromDir, java.io.File toFileOrDir) throws java.io.IOException
java.io.IOException
- if the two paths has no common parent directory
(such as C:\foo.txt
and D:\foo.txt
), or
the the paths are malformed.public static void copyFile(java.io.File src, java.io.File dst, boolean copyLMD) throws java.io.IOException
copyLMD
- tells if the last modification time of the original
file will be copied too.java.io.IOException
public static void copyFile(java.io.File src, java.io.File dst) throws java.io.IOException
copyFile(src, dst, true))
.java.io.IOException
public static boolean isInsideOrEquals(java.io.File file, java.io.File ascendant)
file
is inside ascendant
or
file
is the same as the ascendant
, otherwise
returns false.public static boolean isInside(java.io.File file, java.io.File ascendant)
file
is inside ascendant
,
otherwise returns false.public static java.io.File resolveRelativeUnixPath(java.io.File root, java.io.File wd, java.lang.String path) throws java.io.IOException
root
- root directorywd
- working directory (current direcory)java.io.IOException
public static java.lang.String compressPath(java.lang.String path, int maxPathLength)
/foo/ba.../baaz.txt
instead of
/foo/bar/blah/blah/blah/baaz.txt
.path
- the path to compress. Either native or UNIX format.maxPathLength
- the maximum length of the result.
Must be at least 4.public static java.lang.String pathToUnixStyle(java.lang.String path)
public static java.lang.String removeSlashPrefix(java.lang.String path)
public static java.lang.String getFileExtension(java.lang.String name)
null
.name
- The file name or path. If null
, null
is returned.public static java.lang.String getLowerCaseFileExtension(java.lang.String name)
getFileExtension(String)
, but also converts the result to lower case.public static java.lang.String pathPatternToPerl5Regex(java.lang.String text)
*
,
?
) it understands **
, that is the same as
in Ant. It assumes that the paths what you will later match
with the pattern are always starting with slash (they are absolute paths
to an imaginary base).public static java.lang.String loadString(java.io.InputStream in, java.lang.String charset) throws java.io.IOException
java.io.IOException
public static byte[] loadByteArray(java.io.InputStream in) throws java.io.IOException
java.io.IOException