public class FileUtil extends Object
| Modifier and Type | Method and Description |
|---|---|
static void |
cleanDirectory(File directoryFile) |
static void |
copy(File sourceFile,
File targetFile) |
static void |
copy(Path sourcePath,
Path targetPath) |
static void |
copyDirectoryIfNotExists(File sourceDir,
File targetDir) |
static void |
createDirectory(File directory) |
static File |
createTempDirectory() |
static void |
downloadRemotes(File outputDirectory,
List<String> remotes,
KitLogger log) |
static String |
getAbsolutePath(String fileName)
Returns the absolute path to a file with name
fileName |
static String |
getAbsolutePath(URL url)
Returns the absolute path to a resource addressed by the given
url |
static String |
getRelativeFilePath(String oldFilePath,
String newFilePath)
Adapted from https://github.com/sonatype/plexus-utils/blob/5ba6cfcca911200b5b9d2b313bb939e6d7cbbac6/src/main/java/org/codehaus/plexus/util/PathTool.java#L302
|
static File |
getRelativePath(File baseDir,
File file) |
static List<File> |
listFilesAndDirsRecursivelyInDirectory(File directory) |
static String |
stripPostfix(String text,
String postfix) |
static String |
stripPrefix(String text,
String prefix) |
static String |
trimWildcardCharactersFromPath(String filePath) |
public static File createTempDirectory()
public static String getAbsolutePath(String fileName)
fileNamefileName - the name of a filepublic static String getAbsolutePath(URL url)
urlurl - resource URLpublic static void downloadRemotes(File outputDirectory, List<String> remotes, KitLogger log)
public static void cleanDirectory(File directoryFile) throws IOException
IOExceptionpublic static String getRelativeFilePath(String oldFilePath, String newFilePath)
This method can calculate the relative path between two paths on a file system.
getRelativeFilePath( null, null ) = ""
getRelativeFilePath( null, "/usr/local/java/bin" ) = ""
getRelativeFilePath( "/usr/local", null ) = ""
getRelativeFilePath( "/usr/local", "/usr/local/java/bin" ) = "java/bin"
getRelativeFilePath( "/usr/local", "/usr/local/java/bin/" ) = "java/bin"
getRelativeFilePath( "/usr/local/java/bin", "/usr/local/" ) = "../.."
getRelativeFilePath( "/usr/local/", "/usr/local/java/bin/java.sh" ) = "java/bin/java.sh"
getRelativeFilePath( "/usr/local/java/bin/java.sh", "/usr/local/" ) = "../../.."
getRelativeFilePath( "/usr/local/", "/bin" ) = "../../bin"
getRelativeFilePath( "/bin", "/usr/local/" ) = "../usr/local"
Note: On Windows based system, the / character should be replaced by \ character.oldFilePath - the old file pathnewFilePath - the new file patholdFilePath.public static void copy(File sourceFile, File targetFile) throws IOException
IOExceptionpublic static void copy(Path sourcePath, Path targetPath) throws IOException
IOExceptionpublic static void copyDirectoryIfNotExists(File sourceDir, File targetDir) throws IOException
IOExceptionpublic static List<File> listFilesAndDirsRecursivelyInDirectory(File directory)
public static void createDirectory(File directory) throws IOException
IOExceptionCopyright © 2024. All rights reserved.