public final class Files extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
Files.DownloadCycleException |
| Modifier and Type | Method and Description |
|---|---|
static void |
assertDirectoryExists(File file)
Throws an exception if the given file does not exist
|
static void |
assertExists(File file)
Throws an exception if the given file or directory does not exist
|
static void |
assertFileExists(File file)
Throws an exception if the given file does not exist
|
static void |
copy(File source,
File target)
|
static void |
copy(InputStream is,
OutputStream os)
Copy the
InputStream to the OutputStream. |
static File |
createTempFile(String path)
Creates a temporary file.
|
static String |
getFileExtension(File file) |
static String |
getFileExtension(String path)
Returns the file extension of the file name of the path or null
|
static String |
getFileName(String path)
Returns the file name part of the path
|
static String |
getRelativePath(File rootDir,
File file) |
static boolean |
isDirectory(File file)
Returns true if the given file is of type directory and exists
|
static boolean |
isFile(File file)
Returns true if the given file is of type file and exists
|
static boolean |
isWindows()
Returns true, if the OS is windows
|
static String |
normalizePath(String path)
Normalizes the path to cater for Windows and other platforms
|
static String |
normalizePath(String path,
char from,
char to) |
static byte[] |
readBytes(File file)
Reads a
File and returns the data as a byte array |
static byte[] |
readBytes(InputStream in)
Reads an
InputStream and returns the data as a byte array |
static List<String> |
readLines(File file)
Reads a
File and returns the list of lines |
static int |
recursiveDelete(File file)
Recursively deletes the given file whether its a file or directory returning the number
of files deleted
|
static void |
recursiveDelete(File file,
FileFilter filter)
Recursively deletes the file and any children files if its a directory
|
static String |
stripLeadingSeparator(String name)
Strip any leading separators
|
static String |
toString(File file)
Reads a
File and returns a . |
static String |
toString(File file,
Charset charset)
Reads a
File and returns a . |
static String |
toString(InputStream inputStream)
Reads an
InputStream and returns a . |
static String |
toString(InputStream inputStream,
Charset charset)
Reads an
InputStream and returns a . |
static File |
urlToFile(String url,
String tempFilePrefix,
String tempFilePostfix) |
static File |
urlToFile(URL url,
String tempFilePrefix,
String tempFilePostfix)
Attempts to convert a URL to a file or copies the URL to a temporary file if it can't be easily converted
|
static void |
writeLines(File file,
List<String> lines)
Writes the given lines to the
File |
static void |
writeToFile(File file,
byte[] content)
|
static void |
writeToFile(File file,
String content,
Charset charset)
|
public static boolean isFile(File file)
public static boolean isDirectory(File file)
public static String normalizePath(String path)
public static boolean isWindows()
public static String stripLeadingSeparator(String name)
public static String getFileExtension(String path)
public static File createTempFile(String path) throws IOException
IOExceptionpublic static String toString(File file, Charset charset) throws IOException
File and returns a .IOExceptionpublic static String toString(InputStream inputStream) throws IOException
InputStream and returns a .IOExceptionpublic static String toString(InputStream inputStream, Charset charset) throws IOException
InputStream and returns a .IOExceptionpublic static List<String> readLines(File file) throws IOException
File and returns the list of linesIOExceptionpublic static void writeLines(File file, List<String> lines) throws IOException
FileIOExceptionpublic static byte[] readBytes(File file) throws IOException
File and returns the data as a byte arrayIOExceptionpublic static byte[] readBytes(InputStream in) throws IOException
InputStream and returns the data as a byte arrayIOExceptionpublic static String toString(File file) throws IOException
File and returns a .IOExceptionpublic static void writeToFile(File file, String content, Charset charset) throws IOException
IOExceptionpublic static void writeToFile(File file, byte[] content) throws IOException
IOExceptionpublic static void copy(File source, File target) throws IOException
IOExceptionpublic static void copy(InputStream is, OutputStream os) throws IOException
InputStream to the OutputStream.IOExceptionpublic static String getRelativePath(File rootDir, File file) throws IOException
IOExceptionpublic static void assertExists(File file)
public static void assertFileExists(File file)
public static void assertDirectoryExists(File file)
public static int recursiveDelete(File file)
public static void recursiveDelete(File file, FileFilter filter)
public static File urlToFile(String url, String tempFilePrefix, String tempFilePostfix) throws IOException
IOExceptionpublic static File urlToFile(URL url, String tempFilePrefix, String tempFilePostfix) throws IOException
IOExceptionCopyright © 2011–2014 Red Hat. All rights reserved.