Class FileUtil
- java.lang.Object
-
- org.zeroturnaround.javarebel.integration.util.FileUtil
-
public class FileUtil extends Object
Helper methods for managing operations with the file system..- Author:
- Rein Raudjärv
-
-
Constructor Summary
Constructors Constructor Description FileUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleancanWriteToDir(File dir)static voidcopyAndClose(InputStream in, File outputFile)Copies the given stream to a file.static voidcopyFile(File srcFile, File destFile)Copies the given file to a new location.static voidforceDelete(File file)Deletes the given file or directory.static byte[]getBytes(File f)static StringgetExtension(File file)Returns the extension of a given file ornullif the file has no extension.static Collection<File>getUniqueParentDirs(Collection<File> files)
-
-
-
Method Detail
-
copyFile
public static void copyFile(File srcFile, File destFile) throws IOException
Copies the given file to a new location.If the destination file already exists it will be overwritten.
- Parameters:
srcFile- source file (notnull, must exist).destFile- destination file (notnull, parent directory must exist).- Throws:
IOException
-
copyAndClose
public static void copyAndClose(InputStream in, File outputFile) throws IOException
Copies the given stream to a file.If the destination file already exists it will be overwritten.
- Parameters:
in- source stream (notnull).outputFile- destination file (notnull, parent directory must exist).- Throws:
IOException
-
forceDelete
public static void forceDelete(File file) throws IOException
Deletes the given file or directory. Throws an IOException in case of any error.- Throws:
IOException
-
getExtension
public static String getExtension(File file)
Returns the extension of a given file ornullif the file has no extension.- Parameters:
file- input file (notnull).
-
canWriteToDir
public static boolean canWriteToDir(File dir)
-
getBytes
public static byte[] getBytes(File f)
-
getUniqueParentDirs
public static Collection<File> getUniqueParentDirs(Collection<File> files)
- Parameters:
files- Collection of files- Returns:
- files containing only parent directories. For example if there are [C:\weblogic\x\y, C:\weblogic\, C:\tomcat], then result is [C:\weblogic\, C:\tomcat], because C:\weblogic\x\y is a subdirectory of C:\weblogic
-
-