Package org.apache.any23.util
Class FileUtils
- java.lang.Object
-
- org.apache.any23.util.FileUtils
-
public class FileUtils extends Object
Utility class for handling files.- Author:
- Michele Mostarda (mostarda@fbk.eu)
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcp(File src, File dest)Copies a filesrcto thedest.static voidcp(InputStream is, File dest)Copies the content of the input stream within the given dest file.static voiddumpContent(File f, String content)Dumps the given string within a file.static voiddumpContent(File f, Throwable t)Dumps the stack trace of the given exception into the specified file.static File[]listFilesRecursively(File dir, FilenameFilter filenameFilter)Lists the content of a dir applying the specified filter.static Filemv(File target, File dest)Moves atargetfile to a newdestlocation.static StringreadFileContent(File f)Returns the content of a file a single string.static String[]readFileLines(File f)Returns all the lines of a file.static StringreadResourceContent(Class clazz, String resource)Reads a resource file and returns the content as a string.static StringreadResourceContent(String resource)Reads a resource file and returns the content as a string.
-
-
-
Method Detail
-
mv
public static File mv(File target, File dest)
Moves atargetfile to a newdestlocation.- Parameters:
target- file to be moved.dest- dest dir.- Returns:
- destination file.
-
cp
public static void cp(InputStream is, File dest)
Copies the content of the input stream within the given dest file. The dest file must not exist.- Parameters:
is-InputStreamto copydest- detination to copy it to.
-
cp
public static void cp(File src, File dest) throws FileNotFoundException
Copies a filesrcto thedest.- Parameters:
src- source file.dest- destination file.- Throws:
FileNotFoundException- if file cannot be copied or created.
-
dumpContent
public static void dumpContent(File f, String content) throws IOException
Dumps the given string within a file.- Parameters:
f- file target.content- content to be dumped.- Throws:
IOException- if there is an error dumping the content
-
dumpContent
public static void dumpContent(File f, Throwable t) throws IOException
Dumps the stack trace of the given exception into the specified file.- Parameters:
f- file to generate dump.t- exception to be dumped.- Throws:
IOException- if there is an error dumping the content
-
readResourceContent
public static String readResourceContent(Class clazz, String resource) throws IOException
Reads a resource file and returns the content as a string.- Parameters:
clazz- the class to use load the resource.resource- the resource to be load.- Returns:
- the string representing the file content.
- Throws:
IOException- if there is an error loading the resource
-
readResourceContent
public static String readResourceContent(String resource) throws IOException
Reads a resource file and returns the content as a string.- Parameters:
resource- the resource to be load.- Returns:
- the string representing the file content.
- Throws:
IOException- if there is an error loading the resource
-
readFileContent
public static String readFileContent(File f) throws IOException
Returns the content of a file a single string.- Parameters:
f- the file to read.- Returns:
- the content of file.
- Throws:
IOException- if an error occurs while locating or accessing the file.
-
readFileLines
public static String[] readFileLines(File f) throws IOException
Returns all the lines of a file.- Parameters:
f- the file to read.- Returns:
- a not
nullarray with notnullline strings. - Throws:
IOException- if an error occurs while locating or accessing the file.
-
listFilesRecursively
public static File[] listFilesRecursively(File dir, FilenameFilter filenameFilter)
Lists the content of a dir applying the specified filter.- Parameters:
dir- directory root.filenameFilter- filter to be applied.- Returns:
- list of matching files.
-
-