public final class FilteringUtils extends Object
Modifier and Type | Method and Description |
---|---|
static void |
copyFile(File from,
File to,
String encoding,
FilterWrapper[] wrappers,
boolean overwrite)
If wrappers is null or empty, the file will be copy only if to.lastModified() < from.lastModified() or if
overwrite is true
|
static String |
escapeWindowsPath(String val) |
static String |
getRelativeFilePath(String oldPath,
String newPath)
This method can calculate the relative path between two paths on a file system.
|
static File |
resolveFile(File baseFile,
String filename)
Resolve a file
filename to its canonical form. |
public static String escapeWindowsPath(String val)
val
- The value to be escaped.public static File resolveFile(File baseFile, String filename)
filename
to its canonical form. If filename
is
relative (doesn't start with /
), it is resolved relative to
baseFile
. Otherwise it is treated as a normal root-relative path.baseFile
- where to resolve filename
from, if filename
is relativefilename
- absolute or relative file path to resolveFile
of filename
public static String getRelativeFilePath(String oldPath, String newPath)
This method can calculate the relative path between two paths on a file system.
PathTool.getRelativeFilePath( null, null ) = "" PathTool.getRelativeFilePath( null, "/usr/local/java/bin" ) = "" PathTool.getRelativeFilePath( "/usr/local", null ) = "" PathTool.getRelativeFilePath( "/usr/local", "/usr/local/java/bin" ) = "java/bin" PathTool.getRelativeFilePath( "/usr/local", "/usr/local/java/bin/" ) = "java/bin" PathTool.getRelativeFilePath( "/usr/local/java/bin", "/usr/local/" ) = "../.." PathTool.getRelativeFilePath( "/usr/local/", "/usr/local/java/bin/java.sh" ) = "java/bin/java.sh" PathTool.getRelativeFilePath( "/usr/local/java/bin/java.sh", "/usr/local/" ) = "../../.." PathTool.getRelativeFilePath( "/usr/local/", "/bin" ) = "../../bin" PathTool.getRelativeFilePath( "/bin", "/usr/local/" ) = "../usr/local"Note: On Windows based system, the
/
character should be replaced by \
character.oldPath
- old pathnewPath
- new patholdPath
.public static void copyFile(File from, File to, String encoding, FilterWrapper[] wrappers, boolean overwrite) throws IOException
from
- the file to copyto
- the destination fileencoding
- the file output encoding (only if wrappers is not empty)wrappers
- array of FilterWrapper
overwrite
- if true and wrappers is null or empty, the file will be copied even if
to.lastModified() < from.lastModified()IOException
- if an IO error occurs during copying or filteringCopyright © 2002–2022 The Apache Software Foundation. All rights reserved.