Package org.h2gis.utilities
Class FileUtilities
- java.lang.Object
-
- org.h2gis.utilities.FileUtilities
-
public class FileUtilities extends Object
Utilities for file(s) and directory- Author:
- Erwan Bocher, CNRS, 2020
-
-
Constructor Summary
Constructors Constructor Description FileUtilities()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleandeleteFiles(File directory)Use this method to delete all files in directory recursively without deleting the root directorystatic booleandeleteFiles(File directory, boolean delete)Use this method to delete all files in directory recursively.static StringgetRelativePath(File base, File file)Get the relative path to file, according to the path to basestatic booleanisExtensionWellFormated(File file, String prefix)Check if the file has the good extensionstatic booleanisFileImportable(File file, String prefix)Check if the file is well formatted regarding an extension prefix.static List<String>listFiles(File directory)List all files in a directorystatic List<String>listFiles(File directory, String extension)List all filesstatic FilenewFile(File destinationDir, ZipEntry zipEntry)static voidunzipFile(File zipFile, File directory)Unzip to a directorystatic voidzip(File[] filesToZip, File outFile)Zips the specified filesstatic voidzip(File toZip, File outFile)Zips the specified file or folder
-
-
-
Method Detail
-
deleteFiles
public static boolean deleteFiles(File directory) throws IOException
Use this method to delete all files in directory recursively without deleting the root directory- Parameters:
directory- the directory- Returns:
- true if the directory already exists
- Throws:
IOException
-
deleteFiles
public static boolean deleteFiles(File directory, boolean delete) throws IOException
Use this method to delete all files in directory recursively. The root directory can be deleted- Parameters:
directory- the directorydelete- true to delete the root directory- Returns:
- true if the directory already exists
- Throws:
IOException
-
listFiles
public static List<String> listFiles(File directory, String extension) throws IOException
List all files- Parameters:
directory- the directoryextension- file extension, txt, geojson, shapefile- Returns:
- path of the files
- Throws:
IOException
-
listFiles
public static List<String> listFiles(File directory) throws IOException
List all files in a directory- Parameters:
directory- the directory- Returns:
- path of the files
- Throws:
IOException
-
unzipFile
public static void unzipFile(File zipFile, File directory) throws IOException
Unzip to a directory- Parameters:
zipFile- the zipped filedirectory- the directory to unzi the file- Throws:
FileNotFoundExceptionIOException
-
newFile
public static File newFile(File destinationDir, ZipEntry zipEntry) throws IOException
- Parameters:
destinationDir-zipEntry-- Returns:
- Throws:
IOException
-
zip
public static void zip(File[] filesToZip, File outFile) throws IOException
Zips the specified files- Parameters:
filesToZip-outFile-- Throws:
IOException
-
zip
public static void zip(File toZip, File outFile) throws IOException
Zips the specified file or folder- Parameters:
toZip-outFile-- Throws:
IOException
-
getRelativePath
public static String getRelativePath(File base, File file)
Get the relative path to file, according to the path to base- Parameters:
base-file-- Returns:
-
isFileImportable
public static boolean isFileImportable(File file, String prefix) throws SQLException, FileNotFoundException
Check if the file is well formatted regarding an extension prefix. Check also if the file doesn't exist.- Parameters:
file-prefix-- Returns:
- Throws:
SQLExceptionFileNotFoundException
-
-