Extensions for java.nio.file.Path
appendLines
bufferedReader
Returns a new BufferedReader for reading the content of this file.
fun Path.bufferedReader(
charset: Charset = Charsets.UTF_8,
bufferSize: Int = DEFAULT_BUFFER_SIZE,
vararg options: OpenOption
): BufferedReader
bufferedWriter
Returns a new BufferedWriter for writing the content of this file.
fun Path.bufferedWriter(
charset: Charset = Charsets.UTF_8,
bufferSize: Int = DEFAULT_BUFFER_SIZE,
vararg options: OpenOption
): BufferedWriter
createDirectories
Creates a directory ensuring that all nonexistent parent directories exist by creating them first.
fun Path.createDirectories(
vararg attributes: FileAttribute<*>
): Path
createDirectory
Creates a new directory or throws an exception if there is already a file or directory located by this path.
fun Path.createDirectory(
vararg attributes: FileAttribute<*>
): Path
createFile
Creates a new and empty file specified by this path, failing if the file already exists.
fun Path.createFile(
vararg attributes: FileAttribute<*>
): Path
createSymbolicLinkPointingTo
Creates a new symbolic link located by this path to the given target.
fun Path.createSymbolicLinkPointingTo(
target: Path,
vararg attributes: FileAttribute<*>
): Path
deleteExisting
Deletes the existing file or empty directory specified by this path.
fun Path.deleteExisting()
deleteIfExists
Deletes the file or empty directory specified by this path if it exists.
fun Path.deleteIfExists(): Boolean
exists
Checks if the file located by this path exists.
fun Path.exists(vararg options: LinkOption): Boolean
extension
Returns the extension of this path (not including the dot), or an empty string if it doesn't have one.
val Path.extension: String
fileAttributesView
Returns a file attributes view of a given type V or throws an UnsupportedOperationException if the requested attribute view type is not available..
fun <V : FileAttributeView> Path.fileAttributesView(
vararg options: LinkOption
): V
fileAttributesViewOrNull
Returns a file attributes view of a given type V
or null
if the requested attribute view type is not available.
fun <V : FileAttributeView> Path.fileAttributesViewOrNull(
vararg options: LinkOption
): V?
getAttribute
Reads the value of a file attribute.
fun Path.getAttribute(
attribute: String,
vararg options: LinkOption
): Any?
getLastModifiedTime
Returns the last modified time of the file located by this path.
fun Path.getLastModifiedTime(
vararg options: LinkOption
): FileTime
getOwner
Returns the owner of a file.
fun Path.getOwner(vararg options: LinkOption): UserPrincipal?
getPosixFilePermissions
Returns the POSIX file permissions of the file located by this path.
fun Path.getPosixFilePermissions(
vararg options: LinkOption
): Set<PosixFilePermission>
inputStream
Constructs a new InputStream of this file and returns it as a result.
fun Path.inputStream(vararg options: OpenOption): InputStream
isDirectory
Checks if the file located by this path is a directory.
fun Path.isDirectory(vararg options: LinkOption): Boolean
isExecutable
Checks if the file located by this path exists and is executable.
fun Path.isExecutable(): Boolean
isReadable
Checks if the file located by this path exists and is readable.
fun Path.isReadable(): Boolean
isRegularFile
Checks if the file located by this path is a regular file.
fun Path.isRegularFile(vararg options: LinkOption): Boolean
isSymbolicLink
Checks if the file located by this path exists and is a symbolic link.
fun Path.isSymbolicLink(): Boolean
isWritable
Checks if the file located by this path exists and is writable.
fun Path.isWritable(): Boolean
name
Returns the name of the file or directory denoted by this path as a string, or an empty string if this path has zero path elements.
val Path.name: String
notExists
Checks if the file located by this path does not exist.
fun Path.notExists(vararg options: LinkOption): Boolean
outputStream
Constructs a new OutputStream of this file and returns it as a result.
fun Path.outputStream(
vararg options: OpenOption
): OutputStream
readAttributes
Reads a file's attributes of the specified type A in bulk.
fun <A : BasicFileAttributes> Path.readAttributes(
vararg options: LinkOption
): A
Reads the specified list of attributes of a file in bulk.
fun Path.readAttributes(
attributes: String,
vararg options: LinkOption
): Map<String, Any?>
reader
Returns a new InputStreamReader for reading the content of this file.
fun Path.reader(
charset: Charset = Charsets.UTF_8,
vararg options: OpenOption
): InputStreamReader
setAttribute
Sets the value of a file attribute.
fun Path.setAttribute(
attribute: String,
value: Any?,
vararg options: LinkOption
): Path
setOwner
Sets the file owner to the specified value.
fun Path.setOwner(value: UserPrincipal): Path
setPosixFilePermissions
Sets the POSIX file permissions for the file located by this path.
fun Path.setPosixFilePermissions(
value: Set<PosixFilePermission>
): Path
writeBytes
Writes an array of bytes to this file.
fun Path.writeBytes(
array: ByteArray,
vararg options: OpenOption)
writeLines
Write the specified collection of char sequences lines to a file terminating each one with the platform's line separator.
fun Path.writeLines(
lines: Iterable<CharSequence>,
charset: Charset = Charsets.UTF_8,
vararg options: OpenOption
): Path
Write the specified sequence of char sequences lines to a file terminating each one with the platform's line separator.
fun Path.writeLines(
lines: Sequence<CharSequence>,
charset: Charset = Charsets.UTF_8,
vararg options: OpenOption
): Path
writer
Returns a new OutputStreamWriter for writing the content of this file.
fun Path.writer(
charset: Charset = Charsets.UTF_8,
vararg options: OpenOption
): OutputStreamWriter