public class FileUtils extends Object
| Constructor and Description |
|---|
FileUtils() |
| Modifier and Type | Method and Description |
|---|---|
static void |
closeQuietly(InputStream is)
Closes the stream, if possible, suppressing any exception.
|
static void |
closeQuietly(OutputStream os)
Closes the stream, if possible, suppressing any exception.
|
static void |
closeQuietly(Reader reader)
Closes the reader, if possible, suppressing any exception.
|
static void |
closeQuietly(Writer writer)
Closes the writer, if possible, suppressing any exception.
|
static String |
createPartialFilename(File file,
int numParentDirs)
Creates a partial filename for the given file, based on how many parent
directories should be included.
|
static int |
getDirectoryDepth(File file)
Returns the number of directories that this file object contains.
|
static String |
getExtension(File file)
Returns the extension of the file, if any.
|
static String |
getExtension(String filename)
Returns the extension of the file, if any.
|
public static int getDirectoryDepth(File file)
file - the filepublic static String createPartialFilename(File file, int numParentDirs)
createPartialFilename(new File("/home/some/where/file.txt"), -1)
= /home/some/where/file.txt
createPartialFilename(new File("/home/some/where/file.txt"), 0)
= file.txt
createPartialFilename(new File("/home/some/where/file.txt"), 1)
= where/file.txt
createPartialFilename(new File("/home/some/where/file.txt"), 2)
= some/where/file.txt
file - the file to create the partial filename fornumParentDirs - the number of parent directories to include in
the partial name, -1 returns the absolute
filenamepublic static void closeQuietly(InputStream is)
is - the stream to closepublic static void closeQuietly(OutputStream os)
os - the stream to closepublic static void closeQuietly(Reader reader)
reader - the reader to closepublic static void closeQuietly(Writer writer)
writer - the writer to closepublic static String getExtension(File file)
file - the file to get the extension fromCopyright © 2017. All Rights Reserved.