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(bytes: Array[Byte])(implicit openOptions: OpenOptions): File.this.type

    Permalink
  14. def append(text: String)(implicit openOptions: OpenOptions = File.OpenOptions.append, codec: Codec): 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 apply(permission: PosixFilePermission)(implicit linkOptions: LinkOptions = File.LinkOptions.default): Boolean

    Permalink

    test if file has this permission

  19. final def asInstanceOf[T0]: T0

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

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

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

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

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

    Permalink
  25. def byteArray: Array[Byte]

    Permalink
  26. def bytes: Iterator[Byte]

    Permalink
  27. 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")

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

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

    Permalink

    returns

    checksum of this file (or directory) in hex format

  30. def children: Files

    Permalink
  31. 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

  32. def clone(): AnyRef

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

    Permalink

    More Scala friendly way of doing Files.walk

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

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

    Permalink
  36. def contentType: Option[String]

    Permalink
  37. def copyTo(destination: File, overwrite: Boolean = false): destination.type

    Permalink

    returns

    destination

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

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

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

    Permalink
  41. 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)

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

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

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

    Permalink
  45. def entries: Files

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

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

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

    Permalink
  49. 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

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

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

    Permalink
  52. def fileReader: ManagedResource[FileReader]

    Permalink
  53. def fileSystem: FileSystem

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

    Permalink
  55. def finalize(): Unit

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

    Permalink
    Definition Classes
    AnyRef → Any
  57. 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

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

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

    Permalink
  60. def hasExtension: Boolean

    Permalink
  61. def hashCode(): Int

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

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

    Permalink
  64. 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

  65. def isEmpty: Boolean

    Permalink

    returns

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

  66. def isExecutable: Boolean

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

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

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

    Permalink
  70. def isHidden: Boolean

    Permalink
  71. final def isInstanceOf[T0]: Boolean

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

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

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

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

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

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

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

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

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

    Permalink
  81. 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

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

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

  84. def isSameFileAs(that: File): Boolean

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

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

    Permalink
  87. 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

  88. def isSymbolicLink: Boolean

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

    Permalink
  90. def isWriteable: Boolean

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

    Permalink
  92. 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()

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

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

    Permalink
  95. def list: Files

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

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

    Permalink
  98. def loadBytes: Array[Byte]

    Permalink
  99. def md5: String

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

    Permalink

    returns

    destination

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

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

  103. def nameWithoutExtension: String

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

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

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

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

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

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

    Permalink
  110. def newFileReader: FileReader

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

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

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

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

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

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

    Permalink
  117. def newWatchService: WatchService

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

    Permalink
  119. final def notify(): Unit

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

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

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

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

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

    Permalink
  125. 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

  126. def parentOption: Option[File]

    Permalink

    returns

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

  127. val path: Path

    Permalink
  128. def pathAsString: String

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

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

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

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

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

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

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

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

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

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

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

    Permalink
  140. def root: File

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

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

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

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

    Permalink
  145. def sha1: String

    Permalink
  146. def sha256: String

    Permalink
  147. def sha512: String

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

    Permalink
  149. def siblings: Files

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

    Permalink

    returns

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

  151. def symbolicLink: Option[File]

    Permalink

    returns

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

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

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

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

    Permalink
  155. def toString(): String

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

    Permalink
  157. 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

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

    Permalink

    unzip to a temporary zip file

    unzip to a temporary zip file

    returns

    the zip file

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

  160. def uri: URI

    Permalink
  161. final def wait(): Unit

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

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

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  164. 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)

  165. def watchService: ManagedResource[WatchService]

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

    Permalink
  167. def write(bytes: Array[Byte])(implicit openOptions: OpenOptions): File.this.type

    Permalink

    Write byte array to file.

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

    returns

    this

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

    Permalink
  169. 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

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