public class PathUtilities extends Object
Strings to avoid use of File and
Path which may not be supported in all environments in which Graal is embedded. Use in
such environments requires defining a PathUtilitiesProvider service implementation.| Constructor and Description |
|---|
PathUtilities() |
| Modifier and Type | Method and Description |
|---|---|
static String |
archiveAndDelete(String directory,
String zip)
Zips and deletes
directory if it exists. |
static String |
createDirectories(String path)
Creates a directory represented by
path by creating all nonexistent parent
directories first. |
static void |
deleteFile(String path)
Deletes the file or directory denoted by
path. |
static boolean |
exists(String path)
Tests whether the file or directory denoted by
path exists. |
static String |
getAbsolutePath(String path)
Gets the absolute pathname of
path. |
static String |
getParent(String path)
Gets the pathname of
path's parent, or null if path does not have a parent
directory. |
static String |
getPath(String first,
String... more)
Joins a sequence of strings to form a pathname.
|
static boolean |
isDirectory(String path,
boolean followLinks) |
static WritableByteChannel |
openFileChannel(String path,
OpenOption... options)
Opens or creates a file, returning a channel to access the file
path. |
static InputStream |
openInputStream(String path)
Creates an input stream by opening the file
path. |
static OutputStream |
openOutputStream(String path)
Short cut for calling
PathUtilities.openOutputStream(String, boolean) with the arguments
path and false. |
static OutputStream |
openOutputStream(String path,
boolean append)
Creates an output stream to write to the file
path. |
static String |
sanitizeFileName(String name)
Gets a value based on
name that can be passed to PathUtilities.getPath(String, String...)
without causing an InvalidPathException. |
public static String sanitizeFileName(String name)
name that can be passed to PathUtilities.getPath(String, String...)
without causing an InvalidPathException.name with all characters invalid for the current file system replaced by
'_'public static String getPath(String first, String... more)
public static String getAbsolutePath(String path)
path.public static boolean exists(String path)
path exists.public static String createDirectories(String path) throws IOException
path by creating all nonexistent parent
directories first. An exception is not thrown if the directory could not be created because
it already exists. If this method fails, then it may do so after creating some, but not all,
of the parent directories.IOException - if path exists but is not a directory or if some I/O error occurspublic static OutputStream openOutputStream(String path, boolean append) throws IOException
path. If append is true, then
bytes will be written to the end of the file rather than the beginning.
throws IOException if the file exists but is a directory rather than a regular file,
does not exist but cannot be created, or cannot be opened for any other reasonIOExceptionpublic static OutputStream openOutputStream(String path) throws IOException
PathUtilities.openOutputStream(String, boolean) with the arguments
path and false.IOExceptionpublic static String getParent(String path)
path's parent, or null if path does not have a parent
directory.public static WritableByteChannel openFileChannel(String path, OpenOption... options) throws IOException
path.IOExceptionpublic static InputStream openInputStream(String path) throws IOException
path.IOException - if path does not exist, is a directory rather than a regular
file, or for some other reason cannot be opened for readingpublic static String archiveAndDelete(String directory, String zip) throws IOException
directory if it exists.zip - path of the zip file to createIOException - if something goes wrongpublic static boolean isDirectory(String path, boolean followLinks)
public static void deleteFile(String path) throws IOException
path. If path denotes a directory,
then it must be empty in order to be deleted.IOException - if the deletion fails