|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.h2.store.fs.FileUtils
public class FileUtils
This utility class contains utility functions that use the file system abstraction.
Constructor Summary | |
---|---|
FileUtils()
|
Method Summary | |
---|---|
static boolean |
canWrite(java.lang.String fileName)
Check if the file is writable. |
static void |
copy(java.lang.String original,
java.lang.String copy)
Copy a file from one directory to another, or to another file. |
static void |
createDirectories(java.lang.String dir)
Create the directory and all required parent directories. |
static void |
createDirectory(java.lang.String directoryName)
Create a directory (all required parent directories must already exist). |
static boolean |
createFile(java.lang.String fileName)
Create a new file. |
static java.lang.String |
createTempFile(java.lang.String prefix,
java.lang.String suffix,
boolean deleteOnExit,
boolean inTempDir)
Create a new temporary file. |
static void |
delete(java.lang.String path)
Delete a file or directory if it exists. |
static void |
deleteRecursive(java.lang.String path,
boolean tryOnly)
Delete a directory or file and all subdirectories and files. |
static boolean |
exists(java.lang.String fileName)
Checks if a file exists. |
static java.lang.String |
getName(java.lang.String path)
Get the file or directory name (the last element of the path). |
static java.lang.String |
getParent(java.lang.String fileName)
Get the parent directory of a file or directory. |
static boolean |
isAbsolute(java.lang.String fileName)
Check if the file name includes a path. |
static boolean |
isDirectory(java.lang.String fileName)
Check if it is a file or a directory. |
static long |
lastModified(java.lang.String fileName)
Get the last modified date of a file. |
static void |
moveTo(java.lang.String oldName,
java.lang.String newName)
Rename a file if this is allowed. |
static java.util.List<java.lang.String> |
newDirectoryStream(java.lang.String path)
List the files and directories in the given directory. |
static java.io.InputStream |
newInputStream(java.lang.String fileName)
Create an input stream to read from the file. |
static java.io.OutputStream |
newOutputStream(java.lang.String fileName,
boolean append)
Create an output stream to write into the file. |
static java.nio.channels.FileChannel |
open(java.lang.String fileName,
java.lang.String mode)
Open a random access file object. |
static void |
readFully(java.nio.channels.FileChannel channel,
java.nio.ByteBuffer dst)
Fully read from the file. |
static boolean |
setReadOnly(java.lang.String fileName)
Disable the ability to write. |
static long |
size(java.lang.String fileName)
Get the size of a file in bytes This method is similar to Java 7 java.nio.file.attribute.Attributes. |
static java.lang.String |
toRealPath(java.lang.String fileName)
Get the canonical file or directory name. |
static boolean |
tryDelete(java.lang.String fileName)
Try to delete a file (ignore errors). |
static java.lang.String |
unwrap(java.lang.String fileName)
Get the unwrapped file name (without wrapper prefixes if wrapping / delegating file systems are used). |
static void |
writeFully(java.nio.channels.FileChannel channel,
java.nio.ByteBuffer src)
Fully write to the file. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public FileUtils()
Method Detail |
---|
public static boolean exists(java.lang.String fileName)
java.nio.file.Path.exists
.
fileName
- the file name
public static void createDirectory(java.lang.String directoryName)
java.nio.file.Path.createDirectory
.
directoryName
- the directory namepublic static boolean createFile(java.lang.String fileName)
java.nio.file.Path.createFile
,
but returns false instead of throwing a exception if the file already existed.
fileName
- the file name
public static void delete(java.lang.String path)
java.nio.file.Path.deleteIfExists
.
path
- the file or directory namepublic static java.lang.String toRealPath(java.lang.String fileName)
java.nio.file.Path.toRealPath
.
fileName
- the file name
public static java.lang.String getParent(java.lang.String fileName)
java.nio.file.Path.getParent
.
fileName
- the file or directory name
public static boolean isAbsolute(java.lang.String fileName)
java.nio.file.Path.isAbsolute
.
fileName
- the file name
public static void moveTo(java.lang.String oldName, java.lang.String newName)
java.nio.file.Path.moveTo
.
oldName
- the old fully qualified file namenewName
- the new fully qualified file namepublic static java.lang.String getName(java.lang.String path)
java.nio.file.Path.getName
.
path
- the directory and file name
public static java.util.List<java.lang.String> newDirectoryStream(java.lang.String path)
java.nio.file.Path.newDirectoryStream
.
path
- the directory
public static long lastModified(java.lang.String fileName)
java.nio.file.attribute.Attributes.
readBasicFileAttributes(file).lastModified().toMillis()
fileName
- the file name
public static long size(java.lang.String fileName)
java.nio.file.attribute.Attributes.
readBasicFileAttributes(file).size()
fileName
- the file name
public static boolean isDirectory(java.lang.String fileName)
java.nio.file.attribute.Attributes.
readBasicFileAttributes(file).isDirectory()
fileName
- the file or directory name
public static java.nio.channels.FileChannel open(java.lang.String fileName, java.lang.String mode) throws java.io.IOException
java.nio.channels.FileChannel.open
.
fileName
- the file namemode
- the access mode. Supported are r, rw, rws, rwd
java.io.IOException
public static java.io.InputStream newInputStream(java.lang.String fileName) throws java.io.IOException
java.nio.file.Path.newInputStream
.
fileName
- the file name
java.io.IOException
public static java.io.OutputStream newOutputStream(java.lang.String fileName, boolean append)
java.nio.file.Path.newOutputStream
.
fileName
- the file nameappend
- if true, the file will grow, if false, the file will be
truncated first
public static boolean canWrite(java.lang.String fileName)
java.nio.file.Path.checkAccess(AccessMode.WRITE)
fileName
- the file name
public static boolean setReadOnly(java.lang.String fileName)
fileName
- the file name
public static java.lang.String unwrap(java.lang.String fileName)
fileName
- the file name
public static void deleteRecursive(java.lang.String path, boolean tryOnly)
path
- the pathtryOnly
- whether errors should be ignoredpublic static void createDirectories(java.lang.String dir)
dir
- the directory namepublic static void copy(java.lang.String original, java.lang.String copy) throws java.io.IOException
original
- the original file namecopy
- the file name of the copy
java.io.IOException
public static boolean tryDelete(java.lang.String fileName)
fileName
- the file name
public static java.lang.String createTempFile(java.lang.String prefix, java.lang.String suffix, boolean deleteOnExit, boolean inTempDir) throws java.io.IOException
prefix
- the prefix of the file name (including directory name if
required)suffix
- the suffixdeleteOnExit
- if the file should be deleted when the virtual
machine existsinTempDir
- if the file should be stored in the temporary directory
java.io.IOException
public static void readFully(java.nio.channels.FileChannel channel, java.nio.ByteBuffer dst) throws java.io.IOException
channel
- the file channeldst
- the byte buffer
java.io.IOException
public static void writeFully(java.nio.channels.FileChannel channel, java.nio.ByteBuffer src) throws java.io.IOException
channel
- the file channelsrc
- the byte buffer
java.io.IOException
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |