| Constructor and Description |
|---|
FileUtils() |
| Modifier and Type | Method and Description |
|---|---|
static File |
copyStreamToFile(InputStream stream,
File output)
Helper function for writing a text stream to a file.
|
static File |
copyStreamToFileBinary(InputStream stream,
File output)
Helper function for writing a binary stream to a file.
|
static int |
countLines(File filename)
Count the number of newlines in the given file
|
static boolean |
deleteRecursive(File dir)
Recursively delete a directory
|
static void |
downloadURL(URL url,
File file)
Download the contents of the given URL to the given file
|
static File[] |
findRecursive(File start,
FilenameFilter filenameFilter)
Using
File.listFiles(FilenameFilter) find a file in the directory recursively (i.e. |
static boolean |
isJarResource(String resourceURL)
Returns whether the given resource is a jar resource.
|
static boolean |
isJarResource(URL resource)
Returns whether the given resource is a jar resource.
|
static BufferedReader |
read(File file)
Utility method for quickly create a
BufferedReader for
a given file. |
static String |
readall(File file)
Utility method for reading a whole file into a single string.
|
static String |
readall(InputStream stream)
Utility method for reading a whole file into a single string.
|
static String |
readall(InputStream stream,
String encoding)
Utility method for reading a whole file into a single string.
|
static String[] |
readlines(File file) |
static String[] |
readlines(File file,
String encoding) |
static String[] |
readlines(InputStream stream) |
static String[] |
readlines(InputStream stream,
String encoding) |
static File |
unpackJarFile(URL resource)
Given a JAR Resource, this method will unpack the file to
a temporary file and return the temporary file location.
|
static File |
unpackJarFile(URL resource,
boolean deleteOnExit)
Given a JAR Resource, this method will unpack the file to
a temporary file and return the temporary file location.
|
static void |
unpackJarFile(URL resource,
File destination,
boolean deleteOnExit)
Given a JAR resource, this method will unpack the file
to the given destination.
|
public FileUtils()
public static boolean deleteRecursive(File dir)
dir - public static void downloadURL(URL url, File file) throws IOException
url - The URL to download fromfile - The target fileIOException - if an error occurspublic static BufferedReader read(File file) throws IOException
BufferedReader for
a given file.file - The fileIOException - if an error occurspublic static String readall(InputStream stream) throws IOException
stream - The streamIOException - if an error occurspublic static String readall(InputStream stream, String encoding) throws IOException
stream - The streamencoding - the charset of InputStreamReaderIOException - if an error occurspublic static String readall(File file) throws IOException
file - The fileIOException - if an error occurspublic static File copyStreamToFile(InputStream stream, File output) throws IOException
stream - the stream will be consumedoutput - fileIOExceptionpublic static File copyStreamToFileBinary(InputStream stream, File output) throws IOException
stream - The stream to be consumed.output - The file to output toIOExceptionpublic static File unpackJarFile(URL resource) throws IOException
resource - The resource to unpackIOException - If the temporary file could not be created.public static File unpackJarFile(URL resource, boolean deleteOnExit) throws IOException
resource - The resource to unpackdeleteOnExit - Whether to delete the temporary file on exitIOException - If the temporary file could not be created.public static void unpackJarFile(URL resource, File destination, boolean deleteOnExit)
resource - The resource to unpack.destination - The destination filedeleteOnExit - Whether to delete the unpacked file on exit.public static boolean isJarResource(URL resource)
resource - The resource to test.public static boolean isJarResource(String resourceURL)
resourceURL - The resource to test.public static int countLines(File filename)
filename - The filepublic static File[] findRecursive(File start, FilenameFilter filenameFilter)
File.listFiles(FilenameFilter) find a file in the directory recursively (i.e. following directories down).start - filenameFilter - public static String[] readlines(File file) throws IOException
file - the file to read fromIOExceptionpublic static String[] readlines(File file, String encoding) throws IOException
file - the file to read fromencoding - IOExceptionpublic static String[] readlines(InputStream stream) throws IOException
stream - the file to read fromIOExceptionpublic static String[] readlines(InputStream stream, String encoding) throws IOException
stream - the file to read fromencoding - the inputstream encodingIOException