public class FileUtil extends Object
Constructor and Description |
---|
FileUtil() |
Modifier and Type | Method and Description |
---|---|
static String |
compressPath(String path,
int maxPathLength)
Returns a compressed version of the path.
|
static void |
copyFile(File src,
File dst)
Same as
copyFile(src, dst, true)) . |
static void |
copyFile(File src,
File dst,
boolean copyLMD)
Copies a file; silently overwrites the destination if already exists.
|
static String |
getRelativePath(File fromDir,
File toFileOrDir)
Reaturns the path of a file or directory relative to a directory,
in native format.
|
static boolean |
isInside(File file,
File ascendant)
Returns true if
file is inside ascendant ,
otherwise returns false. |
static boolean |
isInsideOrEquals(File file,
File ascendant)
Returns true if
file is inside ascendant or
file is the same as the ascendant , otherwise
returns false. |
static byte[] |
loadByteArray(InputStream in) |
static String |
loadString(InputStream in,
String charset) |
static String |
pathPatternToPerl5Regex(String text)
Converts UN*X style path to regular expression (originally, for Perl 5 dialect, but also works for Java's
dialect).
|
static String |
pathToUnixStyle(String path)
Brings the path to UNI*X style format, so that it can be handled
with path pattern handling functions.
|
static String |
removeSlashPrefix(String path) |
static File |
resolveRelativeUnixPath(File root,
File wd,
String path)
Resolves relative UN*X path based on given root and working directory.
|
public static String getRelativePath(File fromDir, File toFileOrDir) throws IOException
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(File src, File dst, boolean copyLMD) throws IOException
copyLMD
- tells if the last modification time of the original
file will be copied too.IOException
public static void copyFile(File src, File dst) throws IOException
copyFile(src, dst, true))
.IOException
public static boolean isInsideOrEquals(File file, File ascendant)
file
is inside ascendant
or
file
is the same as the ascendant
, otherwise
returns false.public static boolean isInside(File file, File ascendant)
file
is inside ascendant
,
otherwise returns false.public static File resolveRelativeUnixPath(File root, File wd, String path) throws IOException
root
- root directorywd
- working directory (current direcory)IOException
public static String compressPath(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 String pathToUnixStyle(String path)
public static String pathPatternToPerl5Regex(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 absoulte paths
to an imaginary base).public static String loadString(InputStream in, String charset) throws IOException
IOException
public static byte[] loadByteArray(InputStream in) throws IOException
IOException