Package org.goplanit.utils.misc
Class FileUtils
- java.lang.Object
-
- org.goplanit.utils.misc.FileUtils
-
public class FileUtils extends Object
Lightweight File utilities- Author:
- markr
-
-
Constructor Summary
Constructors Constructor Description FileUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
callForEachFileIn(String pathToDir, Consumer<File> callBack)
Call the callback for each file in the directory providedstatic File
create(URL url)
Create from URL given it is a local filestatic boolean
deleteDirectory(File directoryToDelete)
Delete a directory by providing a file that represents a directory.static String
getExtension(File file)
Collect the extension of a file.static String
getFileNameWithoutExtension(String fileName)
Extract the file name without the extension, i.e.static File[]
getFilesWithExtensionFromDir(String pathToDir, String fileExtension)
Collect all files from a directory with the given extension
-
-
-
Field Detail
-
DOT
public static final String DOT
- See Also:
- Constant Field Values
-
ZIP
public static final String ZIP
- See Also:
- Constant Field Values
-
-
Method Detail
-
getExtension
public static String getExtension(File file)
Collect the extension of a file. In case the file is hidden (starts with "." it does not count as extension)- Parameters:
file
- the file to get it from- Returns:
- the extension, if it does not exist return empty string
-
getFilesWithExtensionFromDir
public static File[] getFilesWithExtensionFromDir(String pathToDir, String fileExtension) throws PlanItException
Collect all files from a directory with the given extension- Parameters:
pathToDir
- path to dirfileExtension
- the file extension, e.g. ".xml"- Returns:
- the list of files that match this extension in the dir
- Throws:
PlanItException
- thrown if error
-
getFileNameWithoutExtension
public static String getFileNameWithoutExtension(String fileName)
Extract the file name without the extension, i.e. remove the last part of the string after the last "." encountered- Parameters:
fileName
- to use- Returns:
- fileName without extension
-
callForEachFileIn
public static void callForEachFileIn(String pathToDir, Consumer<File> callBack)
Call the callback for each file in the directory provided- Parameters:
pathToDir
- to checkcallBack
- to use no each file found in dir
-
create
public static File create(URL url)
Create from URL given it is a local file- Parameters:
url
- to use- Returns:
- file
-
deleteDirectory
public static boolean deleteDirectory(File directoryToDelete)
Delete a directory by providing a file that represents a directory. In which case we recursively delete all files in the directory and then the directory itself.- Parameters:
directoryToDelete
- the directory to delete- Returns:
- success of deletion
-
-