public class FileUtils extends Object
Each method is available statically, which means there is no need to instantiate FileUtils. This is more memory efficient and allows for faster runtime then a class that has to be instantiated, first.
| Constructor and Description |
|---|
FileUtils() |
| Modifier and Type | Method and Description |
|---|---|
static String |
getExtension(String path)
Gets the extension of a file name, like ".png" or ".jpg".
|
static File |
getFile(File path,
String fileName)
Create a
File-object from a path and file name. |
static File |
getFile(String path,
String fileName)
Create a
File-object from a path and file name. |
static File |
getFile(URI uri)
Transform a
URI into a File. |
static List<File> |
getFileList(String path,
boolean includeHidden)
Get a list of Files in the give path.
|
static String |
getPath(URI uri)
Get a file path from a URI.
|
static File |
getPathWithoutFilename(File file)
Returns the path only (without file name).
|
static String |
getReadableFileSize(long size)
Get the file size in a human-readable string.
|
static boolean |
isLocal(String uri)
Checks whether the URI represented by the
String uri is a local one. |
public static boolean isLocal(String uri)
String uri is a local one.
Currently, this method checks against the schemes "http(s)" and "ftp(s)". Everything else is considered as "local", though this is of course not necessarily true.
uri - The URI to check against.true if the URI is considered as local, false otherwise.public static String getExtension(String path)
path - The path to get the file extension from. Can also be a String-representation of a URIpublic static File getPathWithoutFilename(File file)
file - File-object to retrieve the path from.File-object.public static File getFile(URI uri)
URI into a File.uri - the URI to convert.File-object.InvalidValueException - if the uri is somehow invalid.public static File getFile(String path, String fileName)
File-object from a path and file name.path - The path of the file.fileName - The name of the file.File-object corresponding to the given path and filename.public static File getFile(File path, String fileName)
File-object from a path and file name.
This method uses the absolute path of the given path File-object to construct the new
File-object representing the desired file.path - A File-object corresponding to a directory, used for the path.fileName - The name of the file.File-object corresponding to the given path and filename.public static String getPath(URI uri)
Get a file path from a URI.
The URI's scheme must be "file://" for this to work, otherwise this method will throw an
InvalidValueException.
uri - The URI-object to extract the path from.URI-objectInvalidValueException - Thrown when either the URI's scheme is not "file", or the returned path is null.public static String getReadableFileSize(long size)
size - The file-size.public static List<File> getFileList(String path, boolean includeHidden)
path - The path to list the files of.includeHidden - Flag whether hidden files should be included or not.Copyright © 2015. All Rights Reserved.