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. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. def /(child: String): File
  4. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  5. def addPermission(permission: PosixFilePermission)(implicit linkOptions: LinkOptions = File.LinkOptions.default): File.this.type
  6. def append(text: String)(implicit openOptions: OpenOptions = File.OpenOptions.append, charset: Charset = File.defaultCharset): File.this.type
  7. def appendByteArray(bytes: Array[Byte])(implicit openOptions: OpenOptions = File.OpenOptions.append): File.this.type
  8. def appendBytes(bytes: Iterator[Byte])(implicit openOptions: OpenOptions = File.OpenOptions.append): File.this.type
  9. def appendLine(line: String = "")(implicit openOptions: OpenOptions = File.OpenOptions.append, charset: Charset = File.defaultCharset): File.this.type
  10. def appendLines(lines: String*)(implicit openOptions: OpenOptions = File.OpenOptions.append, charset: Charset = File.defaultCharset): File.this.type

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

  11. def appendText(text: String)(implicit openOptions: OpenOptions = File.OpenOptions.append, charset: Charset = File.defaultCharset): File.this.type
  12. def applyAndDelete[U](f: (File) ⇒ U): U

    Applies the given function on this and then deletes this file

  13. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  14. def asynchronousFileChannel(implicit openOptions: OpenOptions = File.OpenOptions.default): ManagedResource[AsynchronousFileChannel]
  15. def attributes(implicit linkOptions: LinkOptions = File.LinkOptions.default): BasicFileAttributes
  16. def bufferedReader(implicit charset: Charset = File.defaultCharset): ManagedResource[BufferedReader]
  17. def bufferedWriter(implicit charset: Charset = File.defaultCharset, openOptions: OpenOptions = File.OpenOptions.default): ManagedResource[BufferedWriter]
  18. def byteArray: Array[Byte]
  19. def bytes: Iterator[Byte]
  20. 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.java".changeExtensionTo(".scala")

  21. def chars(implicit charset: Charset = File.defaultCharset): Iterator[Char]
  22. def checksum(algorithm: MessageDigest): String

    returns

    checksum of this file (or directory) in hex format

  23. def children: Files
  24. def clear()(implicit linkOptions: LinkOptions = File.LinkOptions.default): 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

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

    More Scala friendly way of doing Files.walk Note: This is lazy (returns an Iterator) and won't evaluate till we reify the iterator (e.g.

    More Scala friendly way of doing Files.walk Note: This is lazy (returns an Iterator) and won't evaluate till we reify the iterator (e.g. using .toList)

  27. def contains(file: File): Boolean

    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

  28. def contentAsString(implicit charset: Charset = File.defaultCharset): String
  29. def contentType: Option[String]
  30. def copyTo(destination: File, overwrite: Boolean = false)(implicit copyOptions: CopyOptions = File.CopyOptions(overwrite)): destination.type

    returns

    destination

  31. def createChild(child: String, asDirectory: Boolean = false, createParents: Boolean = false)(implicit attributes: Attributes = File.Attributes.default, linkOptions: LinkOptions = File.LinkOptions.default): File
  32. def createDirectories()(implicit attributes: Attributes = File.Attributes.default): File.this.type
  33. def createDirectory()(implicit attributes: Attributes = File.Attributes.default): File.this.type
  34. 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)

  35. 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

  36. def deleteOnExit(): File.this.type
  37. def digest(algorithm: MessageDigest): Array[Byte]
  38. def digestInputStream(digest: MessageDigest)(implicit openOptions: OpenOptions = File.OpenOptions.default): ManagedResource[DigestInputStream]
  39. def dosAttributes(implicit linkOptions: LinkOptions = File.LinkOptions.default): DosFileAttributes
  40. def entries: Files
  41. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  42. def equals(obj: Any): Boolean
    Definition Classes
    File → AnyRef → Any
  43. def exists(implicit linkOptions: LinkOptions = File.LinkOptions.default): Boolean
  44. 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

  45. def extension: Option[String]

    returns

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

  46. def fileChannel(implicit openOptions: OpenOptions = File.OpenOptions.default, attributes: Attributes = File.Attributes.default): ManagedResource[FileChannel]
  47. def fileReader: ManagedResource[FileReader]
  48. def fileSystem: FileSystem
  49. def fileWriter(append: Boolean = false): ManagedResource[FileWriter]
  50. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  51. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
  52. def glob(pattern: String, includePath: Boolean = true)(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

    includePath

    If true, we don't need to set path glob patterns e.g. instead of *

  53. def group(implicit linkOptions: LinkOptions = File.LinkOptions.default): GroupPrincipal
  54. def groupName(implicit linkOptions: LinkOptions = File.LinkOptions.default): String
  55. 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.com/pathikrit/better-files/issues/89

  56. def hashCode(): Int
    Definition Classes
    File → AnyRef → Any
  57. def inputStream(implicit openOptions: OpenOptions = File.OpenOptions.default): ManagedResource[InputStream]
  58. def isChildOf(parent: File): Boolean
  59. def isDirectory(implicit linkOptions: LinkOptions = File.LinkOptions.default): Boolean

    returns

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

  60. def isEmpty(implicit linkOptions: LinkOptions = File.LinkOptions.default): Boolean

    returns

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

  61. def isExecutable: Boolean
  62. def isGroupExecutable(implicit linkOptions: LinkOptions = File.LinkOptions.default): Boolean
  63. def isGroupReadable(implicit linkOptions: LinkOptions = File.LinkOptions.default): Boolean
  64. def isGroupWritable(implicit linkOptions: LinkOptions = File.LinkOptions.default): Boolean
  65. def isHidden: Boolean
  66. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  67. def isLocked(mode: RandomAccessMode, position: Long = 0L, size: Long = Long.MaxValue, isShared: Boolean = false): Boolean
  68. def isOtherExecutable(implicit linkOptions: LinkOptions = File.LinkOptions.default): Boolean
  69. def isOtherReadable(implicit linkOptions: LinkOptions = File.LinkOptions.default): Boolean
  70. def isOtherWritable(implicit linkOptions: LinkOptions = File.LinkOptions.default): Boolean
  71. def isOwnerExecutable(implicit linkOptions: LinkOptions = File.LinkOptions.default): Boolean
  72. def isOwnerReadable(implicit linkOptions: LinkOptions = File.LinkOptions.default): Boolean
  73. def isOwnerWritable(implicit linkOptions: LinkOptions = File.LinkOptions.default): Boolean
  74. def isParentOf(child: File): Boolean
  75. def isReadLocked(position: Long = 0L, size: Long = Long.MaxValue, isShared: Boolean = false): Boolean
  76. 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

    See also

    isOwnerReadable

  77. 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

  78. def isSameContentAs(that: File): Boolean

    returns

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

  79. def isSameFileAs(that: File): Boolean
  80. def isSamePathAs(that: File): Boolean
  81. def isSiblingOf(sibling: File): Boolean
  82. 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

  83. def isSymbolicLink: Boolean
  84. def isWriteLocked(position: Long = 0L, size: Long = Long.MaxValue, isShared: Boolean = false): Boolean
  85. def isWriteable: Boolean
  86. def lastModifiedTime(implicit linkOptions: LinkOptions = File.LinkOptions.default): Instant
  87. def lineIterator(implicit charset: Charset = File.defaultCharset): 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()

  88. def lines(implicit charset: Charset = File.defaultCharset): 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

    returns

    all lines in this file

  89. def linkTo(destination: File, symbolic: Boolean = false)(implicit attributes: Attributes = File.Attributes.default): destination.type
  90. def list: Files
  91. def listRecursively(implicit visitOptions: VisitOptions = File.VisitOptions.default): Files
  92. def listRelativePaths(implicit visitOptions: VisitOptions = File.VisitOptions.default): Iterator[Path]
  93. def loadBytes: Array[Byte]
  94. def md5: String
  95. def moveTo(destination: File, overwrite: Boolean = false): destination.type

    returns

    destination

  96. def name: String

    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

  97. def nameOption: Option[String]

    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

  98. def nameWithoutExtension: String
  99. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  100. def newAsynchronousFileChannel(implicit openOptions: OpenOptions = File.OpenOptions.default): AsynchronousFileChannel
  101. def newBufferedReader(implicit charset: Charset = File.defaultCharset): BufferedReader
  102. def newBufferedWriter(implicit charset: Charset = File.defaultCharset, openOptions: OpenOptions = File.OpenOptions.default): BufferedWriter
  103. def newDigestInputStream(digest: MessageDigest)(implicit openOptions: OpenOptions = File.OpenOptions.default): DigestInputStream
  104. def newFileChannel(implicit openOptions: OpenOptions = File.OpenOptions.default, attributes: Attributes = File.Attributes.default): FileChannel
  105. def newFileReader: FileReader
  106. def newFileWriter(append: Boolean = false): FileWriter
  107. def newInputStream(implicit openOptions: OpenOptions = File.OpenOptions.default): InputStream
  108. def newOutputStream(implicit openOptions: OpenOptions = File.OpenOptions.default): OutputStream
  109. def newPrintWriter(autoFlush: Boolean = false)(implicit openOptions: OpenOptions = File.OpenOptions.default): PrintWriter
  110. def newRandomAccess(mode: RandomAccessMode = File.RandomAccessMode.read): RandomAccessFile
  111. def newScanner(implicit config: Config = Scanner.Config.default): Scanner
  112. def newWatchService: WatchService
  113. def newZipOutputStream(implicit openOptions: OpenOptions = File.OpenOptions.default, charset: Charset = File.defaultCharset): ZipOutputStream
  114. def nonEmpty(implicit linkOptions: LinkOptions = File.LinkOptions.default): Boolean

    returns

    for directories, true if it has no children, false otherwise for files, true if it is a 0-byte file, false otherwise else true if it exists, false otherwise

  115. def notExists(implicit linkOptions: LinkOptions = File.LinkOptions.default): Boolean
  116. final def notify(): Unit
    Definition Classes
    AnyRef
  117. final def notifyAll(): Unit
    Definition Classes
    AnyRef
  118. def outputStream(implicit openOptions: OpenOptions = File.OpenOptions.default): ManagedResource[OutputStream]
  119. def overwrite(text: String)(implicit openOptions: OpenOptions = File.OpenOptions.default, charset: Charset = File.defaultCharset): File.this.type
  120. def owner(implicit linkOptions: LinkOptions = File.LinkOptions.default): UserPrincipal
  121. def ownerName(implicit linkOptions: LinkOptions = File.LinkOptions.default): String
  122. 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

    See also

    parentOption

  123. def parentOption: Option[File]

    returns

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

  124. val path: Path
  125. def pathAsString: String
  126. def pathMatcher(syntax: PathMatcherSyntax, includePath: Boolean)(pattern: String): PathMatcher
  127. def permissions(implicit linkOptions: LinkOptions = File.LinkOptions.default): Set[PosixFilePermission]
  128. def permissionsAsString(implicit linkOptions: LinkOptions = File.LinkOptions.default): String
  129. def posixAttributes(implicit linkOptions: LinkOptions = File.LinkOptions.default): PosixFileAttributes
  130. def printLines(lines: Iterator[Any])(implicit openOptions: OpenOptions = File.OpenOptions.append): File.this.type
  131. def printWriter(autoFlush: Boolean = false)(implicit openOptions: OpenOptions = File.OpenOptions.default): ManagedResource[PrintWriter]
  132. def randomAccess(mode: RandomAccessMode = File.RandomAccessMode.read): ManagedResource[RandomAccessFile]
  133. def readDeserialized[A](implicit openOptions: OpenOptions = File.OpenOptions.default): A

    Deserialize a object using Java's default serialization from this file

  134. def register(service: WatchService, events: Events = File.Events.all): File.this.type
  135. def relativize(destination: File): Path
  136. def removePermission(permission: PosixFilePermission)(implicit linkOptions: LinkOptions = File.LinkOptions.default): File.this.type
  137. def renameTo(newName: String): File
  138. def root: File
  139. def scanner(implicit config: Config = Scanner.Config.default): ManagedResource[Scanner]
  140. def setGroup(group: String): File.this.type
  141. def setOwner(owner: String): File.this.type
  142. def setPermissions(permissions: Set[PosixFilePermission]): File.this.type
  143. def sha1: String
  144. def sha256: String
  145. def sha512: String
  146. def sibling(name: String): File
  147. def siblings: Files
  148. def size(implicit visitOptions: VisitOptions = File.VisitOptions.default): Long

    returns

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

  149. def symbolicLink: Option[File]

    returns

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

  150. def symbolicLinkTo(destination: File)(implicit attributes: Attributes = File.Attributes.default): destination.type
  151. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  152. def testPermission(permission: PosixFilePermission)(implicit linkOptions: LinkOptions = File.LinkOptions.default): Boolean

    test if file has this permission

  153. def toJava: java.io.File
  154. def toString(): String
    Definition Classes
    File → AnyRef → Any
  155. def tokens(implicit config: Config = Scanner.Config.default, charset: Charset = File.defaultCharset): Traversable[String]
  156. 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

  157. def unzip(zipFilter: (ZipEntry) ⇒ Boolean = _ => true)(implicit charset: Charset = File.defaultCharset): File

    unzip to a temporary zip file

    unzip to a temporary zip file

    returns

    the zip file

  158. def unzipTo(destination: File, zipFilter: (ZipEntry) ⇒ Boolean = _ => true)(implicit charset: Charset = File.defaultCharset): destination.type

    Unzips this zip file

    Unzips this zip file

    destination

    destination folder; Creates this if it does not exist

    zipFilter

    An optional param to reject or accept unzipping a file

    returns

    The destination where contents are unzipped

  159. def update(attribute: String, value: Any)(implicit linkOptions: LinkOptions = File.LinkOptions.default): File.this.type

    Set a file attribute e.g.

    Set a file attribute e.g. file("dos:system") = true

  160. def uri: URI
  161. def url: URL
  162. def usingLock[U](mode: RandomAccessMode)(f: (FileChannel) ⇒ U): U
  163. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  164. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  165. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  166. 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

    returns

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

  167. def watchService: ManagedResource[WatchService]
  168. def write(text: String)(implicit openOptions: OpenOptions = File.OpenOptions.default, charset: Charset = File.defaultCharset): File.this.type
  169. 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

    returns

    this

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

    Serialize a object using Java's serializer into this file

  172. def writeText(text: String)(implicit openOptions: OpenOptions = File.OpenOptions.default, charset: Charset = File.defaultCharset): File.this.type
  173. def zip(compressionLevel: Int = Deflater.DEFAULT_COMPRESSION)(implicit charset: Charset = File.defaultCharset): File

    zip to a temp directory

    zip to a temp directory

    returns

    the target directory

  174. def zipIn(files: Files, compressionLevel: Int = Deflater.DEFAULT_COMPRESSION)(charset: Charset = File.defaultCharset): File.this.type

    Adds these files into this zip file Example usage: File("test.zip").zipIn(Seq(file"hello.txt", file"hello2.txt"))

    Adds these files into this zip file Example usage: File("test.zip").zipIn(Seq(file"hello.txt", file"hello2.txt"))

    returns

    this

  175. def zipOutputStream(implicit openOptions: OpenOptions = File.OpenOptions.default, charset: Charset = File.defaultCharset): ManagedResource[ZipOutputStream]
  176. def zipTo(destination: File, compressionLevel: Int = Deflater.DEFAULT_COMPRESSION)(implicit charset: Charset = File.defaultCharset): 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