Package cern.accsoft.steering.jmad.util
Class FileUtil
- java.lang.Object
-
- cern.accsoft.steering.jmad.util.FileUtil
-
public final class FileUtil extends java.lang.Object
This class contains some useful static methods for handling files
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
copyFile(java.io.File source, java.io.File destination)
Copy a file in the File system.static void
createDir(java.io.File dir, boolean globalAccess)
creates the given dir and enables access for all users if wanted.static boolean
deleteDir(java.io.File dir)
recursively deletes the dir and all its contentstatic java.util.Set<java.io.File>
searchInFor(java.nio.file.Path root, java.util.function.Predicate<? super java.nio.file.Path> filterPredicate)
static java.util.List<java.lang.String>
tail(java.io.File file, int requestedNumberOfLines)
Returns the last N lines of the given file.
-
-
-
Method Detail
-
createDir
public static void createDir(java.io.File dir, boolean globalAccess)
creates the given dir and enables access for all users if wanted.- Parameters:
dir
- the dir to createglobalAccess
- if true, give rights to all users, if false permissions are not changed
-
deleteDir
public static boolean deleteDir(java.io.File dir)
recursively deletes the dir and all its content- Parameters:
dir
- the dir to delete- Returns:
- true if successful, false otherwise.
-
copyFile
public static void copyFile(java.io.File source, java.io.File destination) throws java.io.IOException
Copy a file in the File system. UsesFileReader
andFileWriter
to copy the files content.- Parameters:
source
- the source filedestination
- the destination file to save the content to- Throws:
java.io.IOException
-
tail
public static java.util.List<java.lang.String> tail(java.io.File file, int requestedNumberOfLines)
Returns the last N lines of the given file. If the file has less lines than the requested ones, it will return all the lines of the file. Thus, the returned list can also be empty.- Parameters:
file
- the file from which to retrieve the last linesrequestedNumberOfLines
- the number of lines to retrieve- Returns:
- the last lines, as requested.
-
searchInFor
public static java.util.Set<java.io.File> searchInFor(java.nio.file.Path root, java.util.function.Predicate<? super java.nio.file.Path> filterPredicate)
-
-