public abstract class FileUtils extends Object
| Modifier and Type | Field and Description |
|---|---|
static int |
BYTES_TO_MB |
| Constructor and Description |
|---|
FileUtils() |
| Modifier and Type | Method and Description |
|---|---|
static File |
checkFile(String filePath) |
static ByteArrayInputStream |
copy(InputStream source) |
static void |
copyStream(InputStream source,
File destin) |
static void |
copyStream(InputStream source,
OutputStream destin) |
static void |
copyStream(InputStream source,
OutputStream destin,
Boolean closeOutputStream) |
static void |
createFile(String content,
String parentPath,
String fileName) |
static File |
createTempDir() |
static File |
createTempFile() |
static boolean |
exist(String filePath) |
static void |
forceDelete(File file)
Deletes an instance of
File even if it is a directory containing files.If the file is a directory and has contents, then executes itself on every content. |
static long |
getDirectorySize(File directory)
Counts the size of a directory recursively (sum of the length of all files).
|
static float |
getDirectorySizeInMB(File directory) |
static long |
getFileSize(File file) |
static float |
getFileSizeInMB(File file) |
static byte[] |
readAsBytes(File file)
Reads the file and returns a byte array with all the information
|
static byte[] |
readAsBytes(InputStream inputStream)
Reads the inputStream and returns a byte array with all the information
|
static boolean |
renameOrMove(File fileToBeMoved,
File destination)
Renames or moves a determined
File instance to a destination defined by another File instance.Differs from the File.renameTo(File) method in the fact that this method logs if the operation was
successful. |
static void |
safeClose(Closeable closeable) |
static String |
toString(File file)
Receives a File and iterates over all its lines and returns a String.
|
static String |
toString(InputStream in)
Receives an InputStream and iterates over all its lines and returns a String.
|
static String |
toString(InputStream in,
Boolean closeStream) |
static File |
toTempFile(String content) |
static File |
zipFile(String directoryToZipPath) |
public static final int BYTES_TO_MB
public static byte[] readAsBytes(InputStream inputStream) throws IOException
inputStream - The inputStream to be readIOException - The exception thrown when an error reading the inputStream happenspublic static byte[] readAsBytes(File file) throws IOException
file - The file to be readIOException - The exception thrown when an error reading the file happenspublic static File checkFile(String filePath)
filePath - The path to the filepublic static boolean exist(String filePath)
filePath - The file path to the file for verify the existencepublic static void forceDelete(File file)
File even if it is a directory containing files.file - The File to be deleted.File.delete()public static boolean renameOrMove(File fileToBeMoved, File destination)
File instance to a destination defined by another File instance.File.renameTo(File) method in the fact that this method logs if the operation was
successful.fileToBeMoved - The file to be renamed or moved.destination - The File instance that denotes the new locationFile.renameTo(File)public static File createTempFile()
public static File createTempDir()
public static String toString(File file)
file - The filepublic static String toString(InputStream in, Boolean closeStream)
public static String toString(InputStream in)
in - the InputStream to be convertedpublic static void copyStream(InputStream source, File destin)
source - the source InputStreamdestin - the destin Filepublic static void copyStream(InputStream source, OutputStream destin, Boolean closeOutputStream)
source - the source InputStreamdestin - the destin OutputStreamcloseOutputStream - public static void copyStream(InputStream source, OutputStream destin)
source - the source InputStreamdestin - the destin OutputStreampublic static ByteArrayInputStream copy(InputStream source)
source - the source InputStreamByteArrayInputStreampublic static void safeClose(Closeable closeable)
public static long getDirectorySize(File directory)
directory - directory to inspect, must not be nullpublic static long getFileSize(File file)
public static float getDirectorySizeInMB(File directory)
public static float getFileSizeInMB(File file)
Copyright © 2014. All rights reserved.