Class/Object

better.files

File

Related Docs: object File | package files

Permalink

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
Visibility
  1. Public
  2. All

Value Members

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

    Permalink
  2. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ##(): Int

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

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

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

    Permalink
  7. def =!=(that: File): Boolean

    Permalink
  8. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  9. def ===(that: File): Boolean

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

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

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

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

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

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

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

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

    Permalink

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

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

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

    Permalink

    test if file has this permission

  20. final def asInstanceOf[T0]: T0

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

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

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

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

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

    Permalink
  26. def byteArray: Array[Byte]

    Permalink
  27. def bytes: Iterator[Byte]

    Permalink
  28. def changeExtensionTo(extension: String): File

    Permalink

    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")

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

    Permalink
  30. def checksum(algorithm: String): String

    Permalink

    returns

    checksum of this file (or directory) in hex format

  31. def children: Files

    Permalink
  32. def clear(): File.this.type

    Permalink

    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

  33. def clone(): AnyRef

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

    Permalink

    More Scala friendly way of doing Files.walk

  35. def contains(file: File): Boolean

    Permalink

    Check if this directory contains this file

    Check if this directory contains this file

    returns

    true if this is a directory and it contains this file

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

    Permalink
  37. def contentType: Option[String]

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

    Permalink

    returns

    destination

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

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

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

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

    Permalink

    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)

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

    Permalink

    Deletes this file or directory

    Deletes this file or directory

    swallowIOExceptions

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

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

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

    Permalink
  46. def entries: Files

    Permalink
  47. final def eq(arg0: AnyRef): Boolean

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

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

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

    Permalink

    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

  51. def extension: Option[String]

    Permalink

    returns

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

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

    Permalink
  53. def fileReader: ManagedResource[FileReader]

    Permalink
  54. def fileSystem: FileSystem

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

    Permalink
  56. def finalize(): Unit

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

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

    Permalink

    Util to glob from this file's path

    Util to glob from this file's path

    returns

    Set of files that matched

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

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

    Permalink
  61. def hasExtension: Boolean

    Permalink

    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

  62. def hashCode(): Int

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

    Permalink
  64. def isChildOf(parent: File): Boolean

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

    Permalink

    returns

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

  66. def isEmpty: Boolean

    Permalink

    returns

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

  67. def isExecutable: Boolean

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

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

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

    Permalink
  71. def isHidden: Boolean

    Permalink
  72. final def isInstanceOf[T0]: Boolean

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

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

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

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

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

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

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

    Permalink
  80. def isParentOf(child: File): Boolean

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

    Permalink
  82. def isReadable: Boolean

    Permalink

    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

    See also

    isOwnerReadable

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

    Permalink

    returns

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

  84. def isSameContentAs(that: File): Boolean

    Permalink

    returns

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

  85. def isSameFileAs(that: File): Boolean

    Permalink
  86. def isSamePathAs(that: File): Boolean

    Permalink
  87. def isSiblingOf(sibling: File): Boolean

    Permalink
  88. def isSimilarContentAs(that: File): Boolean

    Permalink

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

  89. def isSymbolicLink: Boolean

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

    Permalink
  91. def isWriteable: Boolean

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

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

    Permalink

    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()

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

    Permalink

    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

    returns

    all lines in this file

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

    Permalink
  96. def list: Files

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

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

    Permalink
  99. def loadBytes: Array[Byte]

    Permalink
  100. def md5: String

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

    Permalink

    returns

    destination

  102. def name: String

    Permalink

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

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

  103. def nameOption: Option[String]

    Permalink

    Certain files may not have a name e.g.

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

  104. def nameWithoutExtension: String

    Permalink
  105. final def ne(arg0: AnyRef): Boolean

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

    Permalink
  107. def newBufferedReader(implicit codec: Codec): BufferedReader

    Permalink
  108. def newBufferedSource(implicit codec: Codec): BufferedSource

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

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

    Permalink
  111. def newFileReader: FileReader

    Permalink
  112. def newFileWriter(append: Boolean = false): FileWriter

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

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

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

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

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

    Permalink
  118. def newWatchService: WatchService

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

    Permalink
  120. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  121. final def notifyAll(): Unit

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

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

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

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

    Permalink
  126. def parent: File

    Permalink

    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

    See also

    parentOption

  127. def parentOption: Option[File]

    Permalink

    returns

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

  128. val path: Path

    Permalink
  129. def pathAsString: String

    Permalink
  130. def pathMatcher(syntax: PathMatcherSyntax)(pattern: String): PathMatcher

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

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

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

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

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

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

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

    Permalink
  138. def relativize(destination: File): Path

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

    Permalink
  140. def renameTo(newName: String): File

    Permalink
  141. def root: File

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

    Permalink
  143. def setGroup(group: String): File.this.type

    Permalink
  144. def setOwner(owner: String): File.this.type

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

    Permalink
  146. def sha1: String

    Permalink
  147. def sha256: String

    Permalink
  148. def sha512: String

    Permalink
  149. def sibling(name: String): File

    Permalink
  150. def siblings: Files

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

    Permalink

    returns

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

  152. def symbolicLink: Option[File]

    Permalink

    returns

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

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

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

    Permalink
    Definition Classes
    AnyRef
  155. def toJava: java.io.File

    Permalink
  156. def toString(): String

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

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

    Permalink

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

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

    Permalink

    unzip to a temporary zip file

    unzip to a temporary zip file

    returns

    the zip file

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

    Permalink

    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

  161. def uri: URI

    Permalink
  162. final def wait(): Unit

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

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

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

    Permalink

    Walk the directory tree recursively upto maxDepth

    Walk the directory tree recursively upto maxDepth

    returns

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

  166. def watchService: ManagedResource[WatchService]

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

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

    Permalink

    Write byte array to file.

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

    returns

    this

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

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

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

    Permalink

    zip to a temp directory

    zip to a temp directory

    returns

    the target directory

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

    Permalink

    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