better.files

File

class File extends AnyRef

Scala wrapper around java.nio.files.Path

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. File
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Value Members

  1. def !(implicit codec: Codec): String

  2. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  3. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  4. final def ##(): Int

    Definition Classes
    AnyRef → Any
  5. def /(child: String): File

  6. def <(text: String)(implicit openOptions: OpenOptions = File.OpenOptions.default, codec: Codec): File.this.type

  7. def <<(line: String)(implicit openOptions: OpenOptions = File.OpenOptions.append, codec: Codec): File.this.type

  8. def =!=(that: File): Boolean

  9. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  10. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  11. def ===(that: File): Boolean

  12. def >:(text: String)(implicit openOptions: OpenOptions = File.OpenOptions.default, codec: Codec): File.this.type

  13. def >>:(line: String)(implicit openOptions: OpenOptions = File.OpenOptions.append, codec: Codec): File.this.type

  14. def addPermission(permission: PosixFilePermission)(implicit linkOptions: LinkOptions = File.LinkOptions.default): File.this.type

  15. def append(text: String)(implicit openOptions: OpenOptions = File.OpenOptions.append, codec: Codec): File.this.type

  16. def appendByteArray(bytes: Array[Byte])(implicit openOptions: OpenOptions = File.OpenOptions.append): File.this.type

  17. def appendBytes(bytes: Iterator[Byte])(implicit openOptions: OpenOptions = File.OpenOptions.append): File.this.type

  18. def appendLine(line: String = "")(implicit openOptions: OpenOptions = File.OpenOptions.append, codec: Codec): File.this.type

  19. def appendLines(lines: String*)(implicit openOptions: OpenOptions = File.OpenOptions.append, codec: Codec): File.this.type

    For large number of lines that may not fit in memory, use printLines

    For large number of lines that may not fit in memory, use printLines

    lines
    openOptions
    codec
    returns

  20. def appendText(text: String)(implicit openOptions: OpenOptions = File.OpenOptions.append, codec: Codec): File.this.type

  21. def apply(permission: PosixFilePermission)(implicit linkOptions: LinkOptions = File.LinkOptions.default): Boolean

    test if file has this permission

  22. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  23. def asynchronousFileChannel(implicit openOptions: OpenOptions = File.OpenOptions.default): ManagedResource[AsynchronousFileChannel]

  24. def attributes(implicit linkOptions: LinkOptions = File.LinkOptions.default): BasicFileAttributes

  25. def bufferedReader(implicit codec: Codec): ManagedResource[BufferedReader]

  26. def bufferedSource(implicit codec: Codec): ManagedResource[BufferedSource]

  27. def bufferedWriter(implicit codec: Codec, openOptions: OpenOptions = File.OpenOptions.default): ManagedResource[BufferedWriter]

  28. def byteArray: Array[Byte]

  29. def bytes: Iterator[Byte]

  30. def changeExtensionTo(extension: String): File

    Changes the file-extension by renaming this file; if file does not have an extension, it adds the extension Example usage file"foo.

    Changes the file-extension by renaming this file; if file does not have an extension, it adds the extension Example usage file"foo.java".changeExtensionTo(".scala")

  31. def chars(implicit codec: Codec): Iterator[Char]

  32. def checksum(algorithm: String): String

    returns

    checksum of this file (or directory) in hex format

  33. def children: Files

  34. def clear(): File.this.type

    If this is a directory, remove all its children If its a file, empty the contents

    If this is a directory, remove all its children If its a file, empty the contents

    returns

    this

  35. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  36. def collectChildren(matchFilter: (File) ⇒ Boolean)(implicit visitOptions: VisitOptions = File.VisitOptions.default): Files

    More Scala friendly way of doing Files.

    More Scala friendly way of doing Files.walk

    matchFilter
    returns

  37. def contains(file: File): Boolean

    Check if this directory contains this file

    Check if this directory contains this file

    file
    returns

    true if this is a directory and it contains this file

  38. def contentAsString(implicit codec: Codec): String

  39. def contentType: Option[String]

  40. def copyTo(destination: File, overwrite: Boolean = false)(implicit copyOptions: CopyOptions = File.CopyOptions(overwrite)): destination.type

    destination
    overwrite
    returns

    destination

  41. def createChild(child: String, asDirectory: Boolean = false)(implicit attributes: Attributes = File.Attributes.default, linkOptions: LinkOptions = File.LinkOptions.default): File

  42. def createDirectories()(implicit attributes: Attributes = File.Attributes.default): File.this.type

  43. def createDirectory()(implicit attributes: Attributes = File.Attributes.default): File.this.type

  44. def createIfNotExists(asDirectory: Boolean = false, createParents: Boolean = false)(implicit attributes: Attributes = File.Attributes.default, linkOptions: LinkOptions = File.LinkOptions.default): File.this.type

    Create this file.

    Create this file. If it exists, don't do anything

    asDirectory

    If you want this file to be created as a directory instead, set this to true (false by default)

    createParents

    If you also want all the parents to be created from root to this file (false by defailt)

    attributes
    linkOptions
    returns

  45. def delete(swallowIOExceptions: Boolean = false): File.this.type

    Deletes this file or directory

    Deletes this file or directory

    swallowIOExceptions

    If this is set to true, any exception thrown is swallowed

  46. def digest(algorithmName: String): Array[Byte]

  47. def dosAttributes(implicit linkOptions: LinkOptions = File.LinkOptions.default): DosFileAttributes

  48. def entries: Files

  49. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  50. def equals(obj: Any): Boolean

    Definition Classes
    File → AnyRef → Any
  51. def exists(implicit linkOptions: LinkOptions = File.LinkOptions.default): Boolean

  52. def extension(includeDot: Boolean = true, includeAll: Boolean = false, toLowerCase: Boolean = true): Option[String]

    includeDot

    whether the dot should be included in the extension or not

    includeAll

    whether all extension tokens should be included, or just the last one e.g. for bundle.tar.gz should it be .tar.gz or .gz

    toLowerCase

    to lowercase the extension or not e.g. foo.HTML should have .html or .HTML

    returns

    extension of this file if it is a regular file and has an extension, else None

  53. def extension: Option[String]

    returns

    extension (including the dot) of this file if it is a regular file and has an extension, else None

  54. def fileChannel(implicit openOptions: OpenOptions = File.OpenOptions.default, attributes: Attributes = File.Attributes.default): ManagedResource[FileChannel]

  55. def fileReader: ManagedResource[FileReader]

  56. def fileSystem: FileSystem

  57. def fileWriter(append: Boolean = false): ManagedResource[FileWriter]

  58. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  59. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  60. def glob(pattern: String)(implicit syntax: PathMatcherSyntax = File.PathMatcherSyntax.default, visitOptions: VisitOptions = File.VisitOptions.default): Files

    Util to glob from this file's path

    Util to glob from this file's path

    returns

    Set of files that matched

  61. def group(implicit linkOptions: LinkOptions = File.LinkOptions.default): GroupPrincipal

  62. def groupName(implicit linkOptions: LinkOptions = File.LinkOptions.default): String

  63. def hasExtension: Boolean

    Returns the extension if file is a regular file If file is unreadable or does not exist, it is assumed to be not a regular file See: https://github.

    Returns the extension if file is a regular file If file is unreadable or does not exist, it is assumed to be not a regular file See: https://github.com/pathikrit/better-files/issues/89

    returns

  64. def hashCode(): Int

    Definition Classes
    File → AnyRef → Any
  65. def inputStream(implicit openOptions: OpenOptions = File.OpenOptions.default): ManagedResource[InputStream]

  66. def isChildOf(parent: File): Boolean

  67. def isDirectory(implicit linkOptions: LinkOptions = File.LinkOptions.default): Boolean

    returns

    true if this file (or the file found by following symlink) is a directory

  68. def isEmpty: Boolean

    returns

    true if file is not present or empty directory or 0-bytes file

  69. def isExecutable: Boolean

  70. def isGroupExecutable(implicit linkOptions: LinkOptions = File.LinkOptions.default): Boolean

  71. def isGroupReadable(implicit linkOptions: LinkOptions = File.LinkOptions.default): Boolean

  72. def isGroupWritable(implicit linkOptions: LinkOptions = File.LinkOptions.default): Boolean

  73. def isHidden: Boolean

  74. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  75. def isLocked(mode: RandomAccessMode, position: Long = 0L, size: Long = Long.MaxValue, isShared: Boolean = false): Boolean

  76. def isOtherExecutable(implicit linkOptions: LinkOptions = File.LinkOptions.default): Boolean

  77. def isOtherReadable(implicit linkOptions: LinkOptions = File.LinkOptions.default): Boolean

  78. def isOtherWritable(implicit linkOptions: LinkOptions = File.LinkOptions.default): Boolean

  79. def isOwnerExecutable(implicit linkOptions: LinkOptions = File.LinkOptions.default): Boolean

  80. def isOwnerReadable(implicit linkOptions: LinkOptions = File.LinkOptions.default): Boolean

  81. def isOwnerWritable(implicit linkOptions: LinkOptions = File.LinkOptions.default): Boolean

  82. def isParentOf(child: File): Boolean

  83. def isReadLocked(position: Long = 0L, size: Long = Long.MaxValue, isShared: Boolean = false): Boolean

  84. def isReadable: Boolean

    This differs from the above as this checks if the JVM can read this file even though the OS cannot in certain platforms

    This differs from the above as this checks if the JVM can read this file even though the OS cannot in certain platforms

    returns

    See also

    isOwnerReadable

  85. def isRegularFile(implicit linkOptions: LinkOptions = File.LinkOptions.default): Boolean

    returns

    true if this file (or the file found by following symlink) is a regular file

  86. def isSameContentAs(that: File): Boolean

    returns

    true if this file is exactly same as that file For directories, it checks for equivalent directory structure

  87. def isSameFileAs(that: File): Boolean

  88. def isSamePathAs(that: File): Boolean

  89. def isSiblingOf(sibling: File): Boolean

  90. def isSimilarContentAs(that: File): Boolean

    Almost same as isSameContentAs but uses faster md5 hashing to compare (and thus small chance of false positive) Also works for directories

    Almost same as isSameContentAs but uses faster md5 hashing to compare (and thus small chance of false positive) Also works for directories

    that
    returns

  91. def isSymbolicLink: Boolean

  92. def isWriteLocked(position: Long = 0L, size: Long = Long.MaxValue, isShared: Boolean = false): Boolean

  93. def isWriteable: Boolean

  94. def lastModifiedTime(implicit linkOptions: LinkOptions = File.LinkOptions.default): Instant

  95. def lineIterator(implicit codec: Codec): Iterator[String]

    Iterate over lines in a file (auto-close stream on complete) NOTE: If the iteration is partial, it may leave a stream open If you want partial iteration use @see lines()

    Iterate over lines in a file (auto-close stream on complete) NOTE: If the iteration is partial, it may leave a stream open If you want partial iteration use @see lines()

    codec
    returns

  96. def lines(implicit codec: Codec): Traversable[String]

    Load all lines from this file Note: Large files may cause an OutOfMemory in which case, use the streaming version @see lineIterator

    Load all lines from this file Note: Large files may cause an OutOfMemory in which case, use the streaming version @see lineIterator

    codec
    returns

    all lines in this file

  97. def linkTo(destination: File, symbolic: Boolean = false)(implicit attributes: Attributes = File.Attributes.default): destination.type

  98. def list: Files

  99. def listRecursively(implicit visitOptions: VisitOptions = File.VisitOptions.default): Files

  100. def listRelativePaths(implicit visitOptions: VisitOptions = File.VisitOptions.default): Iterator[Path]

  101. def loadBytes: Array[Byte]

  102. def md5: String

  103. def moveTo(destination: File, overwrite: Boolean = false): destination.type

    destination
    overwrite
    returns

    destination

  104. def name: String

    Name of file Certain files may not have a name e.

    Name of file Certain files may not have a name e.g. root directory - returns empty string in that case

    returns

  105. def nameOption: Option[String]

    Certain files may not have a name e.

    Certain files may not have a name e.g. root directory - returns None in that case

    returns

  106. def nameWithoutExtension: String

  107. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  108. def newAsynchronousFileChannel(implicit openOptions: OpenOptions = File.OpenOptions.default): AsynchronousFileChannel

  109. def newBufferedReader(implicit codec: Codec): BufferedReader

  110. def newBufferedSource(implicit codec: Codec): BufferedSource

  111. def newBufferedWriter(implicit codec: Codec, openOptions: OpenOptions = File.OpenOptions.default): BufferedWriter

  112. def newFileChannel(implicit openOptions: OpenOptions = File.OpenOptions.default, attributes: Attributes = File.Attributes.default): FileChannel

  113. def newFileReader: FileReader

  114. def newFileWriter(append: Boolean = false): FileWriter

  115. def newInputStream(implicit openOptions: OpenOptions = File.OpenOptions.default): InputStream

  116. def newOutputStream(implicit openOptions: OpenOptions = File.OpenOptions.default): OutputStream

  117. def newPrintWriter(autoFlush: Boolean = false)(implicit openOptions: OpenOptions = File.OpenOptions.default): PrintWriter

  118. def newRandomAccess(mode: RandomAccessMode = File.RandomAccessMode.read): RandomAccessFile

  119. def newScanner(implicit config: Config = Scanner.Config.default): Scanner

  120. def newWatchService: WatchService

  121. def notExists(implicit linkOptions: LinkOptions = File.LinkOptions.default): Boolean

  122. final def notify(): Unit

    Definition Classes
    AnyRef
  123. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  124. def outputStream(implicit openOptions: OpenOptions = File.OpenOptions.default): ManagedResource[OutputStream]

  125. def overwrite(text: String)(implicit openOptions: OpenOptions = File.OpenOptions.default, codec: Codec): File.this.type

  126. def owner(implicit linkOptions: LinkOptions = File.LinkOptions.default): UserPrincipal

  127. def ownerName(implicit linkOptions: LinkOptions = File.LinkOptions.default): String

  128. def parent: File

    Return parent of this file NOTE: This API returns null if this file is the root; please use parentOption if you expect to handle roots

    Return parent of this file NOTE: This API returns null if this file is the root; please use parentOption if you expect to handle roots

    returns

    See also

    parentOption

  129. def parentOption: Option[File]

    returns

    Some(parent) of this file or None if this is the root and thus has no parent

  130. val path: Path

  131. def pathAsString: String

  132. def pathMatcher(syntax: PathMatcherSyntax)(pattern: String): PathMatcher

  133. def permissions(implicit linkOptions: LinkOptions = File.LinkOptions.default): Set[PosixFilePermission]

  134. def permissionsAsString(implicit linkOptions: LinkOptions = File.LinkOptions.default): String

  135. def posixAttributes(implicit linkOptions: LinkOptions = File.LinkOptions.default): PosixFileAttributes

  136. def printLines(lines: Iterator[Any])(implicit openOptions: OpenOptions = File.OpenOptions.append): File.this.type

  137. def printWriter(autoFlush: Boolean = false)(implicit openOptions: OpenOptions = File.OpenOptions.default): ManagedResource[PrintWriter]

  138. def randomAccess(mode: RandomAccessMode = File.RandomAccessMode.read): ManagedResource[RandomAccessFile]

  139. def register(service: WatchService, events: Events = File.Events.all): File.this.type

  140. def relativize(destination: File): Path

  141. def removePermission(permission: PosixFilePermission)(implicit linkOptions: LinkOptions = File.LinkOptions.default): File.this.type

  142. def renameTo(newName: String): File

  143. def root: File

  144. def scanner(implicit config: Config = Scanner.Config.default): ManagedResource[Scanner]

  145. def setGroup(group: String): File.this.type

  146. def setOwner(owner: String): File.this.type

  147. def setPermissions(permissions: Set[PosixFilePermission]): File.this.type

  148. def sha1: String

  149. def sha256: String

  150. def sha512: String

  151. def sibling(name: String): File

  152. def siblings: Files

  153. def size(implicit visitOptions: VisitOptions = File.VisitOptions.default): Long

    returns

    file size (for directories, return size of the directory) in bytes

  154. def symbolicLink: Option[File]

    returns

    Some(target) if this is a symbolic link (to target) else None

  155. def symbolicLinkTo(destination: File)(implicit attributes: Attributes = File.Attributes.default): destination.type

  156. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  157. def toJava: java.io.File

  158. def toString(): String

    Definition Classes
    File → AnyRef → Any
  159. def tokens(implicit config: Config = Scanner.Config.default, codec: Codec): Traversable[String]

  160. def touch(time: Instant = Instant.now())(implicit attributes: Attributes = File.Attributes.default, linkOptions: LinkOptions = File.LinkOptions.default): File.this.type

    Similar to the UNIX command touch - create this file if it does not exist and set its last modification time

  161. def unzip()(implicit codec: Codec): File

    unzip to a temporary zip file

    unzip to a temporary zip file

    returns

    the zip file

  162. def unzipTo(destination: File)(implicit codec: Codec): destination.type

    Unzips this zip file

    Unzips this zip file

    destination

    destination folder; Creates this if it does not exist

    returns

    The destination where contents are unzipped

  163. def uri: URI

  164. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  165. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  166. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  167. def walk(maxDepth: Int = Int.MaxValue)(implicit visitOptions: VisitOptions = File.VisitOptions.default): Files

    Walk the directory tree recursively upto maxDepth

    Walk the directory tree recursively upto maxDepth

    maxDepth
    returns

    List of children in BFS maxDepth level deep (includes self since self is at depth = 0)

  168. def watchService: ManagedResource[WatchService]

  169. def write(text: String)(implicit openOptions: OpenOptions = File.OpenOptions.default, codec: Codec): File.this.type

  170. def writeByteArray(bytes: Array[Byte])(implicit openOptions: OpenOptions = File.OpenOptions.default): File.this.type

    Write byte array to file.

    Write byte array to file. For large contents consider using the writeBytes

    bytes
    returns

    this

  171. def writeBytes(bytes: Iterator[Byte])(implicit openOptions: OpenOptions = File.OpenOptions.default): File.this.type

  172. def writeText(text: String)(implicit openOptions: OpenOptions = File.OpenOptions.default, codec: Codec): File.this.type

  173. def zip(compressionLevel: Int = Deflater.DEFAULT_COMPRESSION)(implicit codec: Codec): File

    zip to a temp directory

    zip to a temp directory

    returns

    the target directory

  174. def zipTo(destination: File, compressionLevel: Int = Deflater.DEFAULT_COMPRESSION)(implicit codec: Codec): destination.type

    Zips this file (or directory)

    Zips this file (or directory)

    destination

    The destination file; Creates this if it does not exists

    returns

    The destination zip file

Inherited from AnyRef

Inherited from Any

Ungrouped