object IO
A collection of File, URL, and I/O utility methods.
- Alphabetic
- By Inheritance
- IO
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
val
Newline: String
The newline string for this system, as obtained by the line.separator system property.
-
def
append(file: File, bytes: Array[Byte]): Unit
Appends
bytesto the existing contents offile.Appends
bytesto the existing contents offile. Iffiledoes not exist, it is created, as are any parent directories. -
def
append(file: File, content: String, charset: Charset = defaultCharset): Unit
Appends
contentto the existing contents offileusingcharsetor UTF-8 ifcharsetis not explicitly specified.Appends
contentto the existing contents offileusingcharsetor UTF-8 ifcharsetis not explicitly specified. Iffiledoes not exist, it is created, as are any parent directories. -
def
asFile(url: URL): File
Converts the given URL to a File.
Converts the given URL to a File. If the URL is for an entry in a jar, the File for the jar is returned.
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
- def assertAbsolute(uri: URI): Unit
- def assertAbsolute(f: File): Unit
- def assertDirectories(file: File*): Unit
- def assertDirectory(file: File): Unit
-
def
classLocationFile[T](implicit mf: Manifest[T]): File
Returns the directory or jar file containing the class file for type
T(as determined by an implicit Manifest).Returns the directory or jar file containing the class file for type
T(as determined by an implicit Manifest). If the location cannot be determined, an error is generated. Note that Java standard library classes typically do not have a location associated with them. -
def
classLocationFile(cl: Class[_]): File
Returns the directory or jar file containing the class file
cl.Returns the directory or jar file containing the class file
cl. If the location cannot be determined or it is not a file, an error is generated. Note that Java standard library classes typically do not have a location associated with them. -
def
classfileLocation(cl: Class[_]): URL
Returns a URL for the classfile containing the given class If the location cannot be determined, an error is generated.
-
def
classfileLocation[T](implicit mf: Manifest[T]): URL
Returns a URL for the classfile containing the given class file for type
T(as determined by an implicit Manifest).Returns a URL for the classfile containing the given class file for type
T(as determined by an implicit Manifest). If the location cannot be determined, an error is generated. -
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
- def copy(sources: Traversable[(File, File)], overwrite: Boolean, preserveLastModified: Boolean, preserveExecutable: Boolean): Set[File]
-
def
copy(sources: Traversable[(File, File)], options: CopyOptions): Set[File]
For each pair in
sources, copies the contents of the first File (the source) to the location of the second File (the target).For each pair in
sources, copies the contents of the first File (the source) to the location of the second File (the target).See sbt.io.CopyOptions for docs on the options available.
Any parent directories that do not exist are created. The set of all target files is returned, whether or not they were updated by this method.
- def copy(sources: Traversable[(File, File)]): Set[File]
- def copyDirectory(source: File, target: File, overwrite: Boolean = false, preserveLastModified: Boolean = false, preserveExecutable: Boolean = true): Unit
-
def
copyDirectory(source: File, target: File, options: CopyOptions): Unit
Copies the contents of each file in the
sourcedirectory to the corresponding file in thetargetdirectory.Copies the contents of each file in the
sourcedirectory to the corresponding file in thetargetdirectory.See sbt.io.CopyOptions for docs on the options available.
Files in
targetwithout a corresponding file insourceare left unmodified in any case. Any parent directories that do not exist are created. - def copyDirectory(source: File, target: File): Unit
-
def
copyExecutable(sourceFile: File, targetFile: File): AnyVal
Transfers the executable property of
sourceFiletotargetFile. - def copyFile(sourceFile: File, targetFile: File, preserveLastModified: Boolean = false, preserveExecutable: Boolean = true): Unit
-
def
copyFile(sourceFile: File, targetFile: File, options: CopyOptions): Unit
Copies the contents of
sourceFileto the location oftargetFile, overwriting any existing content.Copies the contents of
sourceFileto the location oftargetFile, overwriting any existing content.See sbt.io.CopyOptions for docs on the options available.
- def copyFile(sourceFile: File, targetFile: File): Unit
-
def
copyLastModified(sourceFile: File, targetFile: File): Boolean
Transfers the last modified time of
sourceFiletotargetFile. -
def
createDirectories(dirs: Traversable[File]): Unit
Creates directories
dirsand all parent directories.Creates directories
dirsand all parent directories. It tries to work around a race condition inFile.mkdirs()by retrying up to a limit. -
def
createDirectory(dir: File): Unit
Creates directory
dirand all parent directories.Creates directory
dirand all parent directories. It tries to work around a race condition inFile.mkdirs()by retrying up to a limit. -
def
createTemporaryDirectory: File
Creates a directory in the default temporary directory with a name generated from a random integer.
-
def
createUniqueDirectory(baseDirectory: File): File
Creates a directory in
baseDirectorywith a name generated from a random integer -
def
defaultCharset: Charset
The default Charset used when not specified: UTF-8.
-
def
delete(file: File): Unit
Deletes
file, recursively if it is a directory. -
def
delete(files: Iterable[File]): Unit
Deletes each file or directory (recursively) in
files. -
def
deleteFilesEmptyDirs(files: Iterable[File]): Unit
Deletes each file or directory in
filesrecursively.Deletes each file or directory in
filesrecursively. Any empty parent directories are deleted, recursively. -
def
deleteIfEmpty(dirs: Set[File]): Unit
Deletes all empty directories in the set.
Deletes all empty directories in the set. Any non-empty directories are ignored.
-
def
directoryURI(uri: URI): URI
Converts an absolute File to a URI.
Converts an absolute File to a URI. The File is converted to a URI (toURI), normalized (normalize), encoded (toASCIIString), and a forward slash ('/') is appended to the path component if it does not already end with a slash.
-
def
directoryURI(dir: File): URI
Converts an absolute File to a URI.
Converts an absolute File to a URI. The File is converted to a URI (toURI), normalized (normalize), encoded (toASCIIString), and a forward slash ('/') is appended to the path component if it does not already end with a slash.
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
def
foldLines[T](in: BufferedReader, init: T)(f: (T, String) ⇒ T): T
Applies
fto each line read frominand the accumulated value of typeT, with initial valueinit.Applies
fto each line read frominand the accumulated value of typeT, with initial valueinit. This method does not closein. -
def
foreachLine(in: BufferedReader)(f: (String) ⇒ Unit): Unit
Applies
fto each line read fromin.Applies
fto each line read fromin. This method does not closein. -
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
-
def
gunzip(input: InputStream, output: OutputStream): Unit
Gunzips the InputStream 'input' and writes it to 'output'.
Gunzips the InputStream 'input' and writes it to 'output'. Neither stream is closed.
-
def
gunzip(in: File, out: File): Unit
Gunzips the file 'in' and writes it to 'out'.
Gunzips the file 'in' and writes it to 'out'. 'in' cannot be the same file as 'out'.
-
def
gzip(input: InputStream, output: OutputStream): Unit
Gzips the InputStream 'in' and writes it to 'output'.
Gzips the InputStream 'in' and writes it to 'output'. Neither stream is closed.
-
def
gzip(in: File, out: File): Unit
Gzips the file 'in' and writes it to 'out'.
Gzips the file 'in' and writes it to 'out'. 'in' cannot be the same file as 'out'.
-
def
gzipFileIn[T](file: File)(f: (InputStream) ⇒ T): T
Applies
fto a buffered gzipInputStreamforfile.Applies
fto a buffered gzipInputStreamforfile. The streams involved are opened before callingfand closed after it returns. The result is the result off. -
def
gzipFileOut[T](file: File)(f: (OutputStream) ⇒ T): T
Applies
fto a buffered gzipOutputStreamforfile.Applies
fto a buffered gzipOutputStreamforfile. The streams involved are opened before callingfand closed after it returns. The result is the result off. -
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
jar(sources: Traversable[(File, String)], outputJar: File, manifest: Manifest): Unit
Creates a jar file.
Creates a jar file.
- sources
The files to include in the jar file paired with the entry name in the jar. Only the pairs explicitly listed are included.
- outputJar
The file to write the jar to.
- manifest
The manifest for the jar.
-
def
listFiles(dir: File): Array[File]
Returns the children of directory
dirin a non-null array. -
def
listFiles(dir: File, filter: java.io.FileFilter): Array[File]
Returns the children of directory
dirthat matchfilterin a non-null array. -
def
listFiles(filter: java.io.FileFilter)(dir: File): Array[File]
Returns the children of directory
dirthat matchfilterin a non-null array. -
def
load(properties: Properties, from: File): Unit
Reads the properties in
fromintoproperties.Reads the properties in
fromintoproperties. Iffromdoes not exist,propertiesis left unchanged. -
def
move(a: File, b: File): Unit
Moves the contents of
ato the location specified byb.Moves the contents of
ato the location specified byb. This method deletes any content already atband creates any parent directories ofbif they do not exist. It will first tryFile.renameToand if that fails, resort to copying and then deleting the original file. In either case, the original File will not exist on successful completion of this method. -
def
move(files: Traversable[(File, File)]): Unit
For each pair in
files, moves the contents of the first File to the location of the second.For each pair in
files, moves the contents of the first File to the location of the second. Seesbt.io.IO$.move(java.io.File,java.io.File):Unitfor the behavior of the individual move operations. -
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
-
def
objectInputStream(wrapped: InputStream, loader: ClassLoader): ObjectInputStream
Constructs an
ObjectInputStreamonwrappedthat usesloaderto load classes.Constructs an
ObjectInputStreamonwrappedthat usesloaderto load classes. See also issue 136. -
def
parseClasspath(s: String): Seq[File]
Parses a classpath String into File entries according to the current platform's path separator.
-
def
pathSplit(s: String): Array[String]
Splits a String around the platform's path separator characters.
-
def
read(file: File, charset: Charset = defaultCharset): String
Reads the full contents of
fileinto a String usingcharsetor UTF-8 ifcharsetis not explicitly specified. -
def
readBytes(in: InputStream): Array[Byte]
Reads the full contents of
ininto a byte array.Reads the full contents of
ininto a byte array. This method does not closein. -
def
readBytes(file: File): Array[Byte]
Reads the full contents of
ininto a byte array. -
def
readLines(in: BufferedReader): List[String]
Reads all of the lines from
in.Reads all of the lines from
in. This method does not closein. -
def
readLines(file: File, charset: Charset = defaultCharset): List[String]
Reads all of the lines in
fileusing the providedcharsetor UTF-8 ifcharsetis not explicitly specified. -
def
readLinesURL(url: URL, charset: Charset = defaultCharset): List[String]
Reads all of the lines from
urlusing the providedcharsetor UTF-8 ifcharsetis not explicitly specified. -
def
readStream(in: InputStream, charset: Charset = defaultCharset): String
Reads the full contents of
ininto a byte array.Reads the full contents of
ininto a byte array. This method does not closein. - def reader[T](file: File, charset: Charset = defaultCharset)(f: (BufferedReader) ⇒ T): T
-
def
relativize(base: File, file: File): Option[String]
Returns the path for
filerelative to directorybaseor None ifbaseis not a parent offile.Returns the path for
filerelative to directorybaseor None ifbaseis not a parent offile. Iffileorbaseare not absolute, they are first resolved against the current working directory. -
def
relativizeFile(base: File, file: File): Option[File]
Returns the relative file for
filerelative to directorybaseor None ifbaseis not a parent offile.Returns the relative file for
filerelative to directorybaseor None ifbaseis not a parent offile. Iffileorbaseare not absolute, they are first resolved against the current working directory. -
def
resolve(base: File, f: File): File
Resolves
fagainstbase, which must be an absolute directory.Resolves
fagainstbase, which must be an absolute directory. The result is guaranteed to be absolute. Iffis absolute, it is returned without changes. -
def
split(name: String): (String, String)
Splits the given string into base and extension strings.
Splits the given string into base and extension strings. If
namecontains no period, the base string is the input string and the extension is the empty string. Otherwise, the base is the substring up until the last period (exclusive) and the extension is the substring after the last period.For example,
split("Build.scala") == ("Build", "scala") -
def
stash[T](files: Set[File])(f: ⇒ T): T
Move the provided files to a temporary location.
Move the provided files to a temporary location. If 'f' returns normally, delete the files. If 'f' throws an Exception, return the files to their original location.
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
- val temporaryDirectory: File
-
def
toFile(url: URL): File
Constructs a File corresponding to
url, which must have a scheme offile.Constructs a File corresponding to
url, which must have a scheme offile. This method properly works around an issue with a simple conversion to URI and then to a File.On Windows this can accept the following patterns of URLs:
val u0 = new URL("file:C:\\Users\\foo/.sbt/preloaded"),val u1 = new URL("file:/C:\\Users\\foo/.sbt/preloaded"),val u2 = new URL("file://unc/Users/foo/.sbt/preloaded"),val u3 = new URL("file:///C:\\Users\\foo/.sbt/preloaded"), andval u4 = new URL("file:////unc/Users/foo/.sbt/preloaded"). -
def
toString(): String
- Definition Classes
- AnyRef → Any
-
def
toURI(f: File): URI
Converts the given File to a URI.
Converts the given File to a URI. If the File is relative, the URI is relative, unlike File.toURI
-
def
touch(file: File, setModified: Boolean = true): Unit
Creates a file at the given location if it doesn't exist.
Creates a file at the given location if it doesn't exist. If the file already exists and
setModifiedis true, this method sets the last modified time to the current time. -
def
touch(files: Traversable[File]): Unit
Each input file in
filesis created if it doesn't exist.Each input file in
filesis created if it doesn't exist. If a file already exists, the last modified time is set to the current time. It is not guaranteed that all files will have the same last modified time after this call. -
def
transfer(in: InputStream, out: OutputStream): Unit
Copies all bytes from the given input stream to the given output stream.
Copies all bytes from the given input stream to the given output stream. Neither stream is closed.
-
def
transfer(in: InputStream, to: File): Unit
Copies all bytes from the given input stream to the given File.
Copies all bytes from the given input stream to the given File. The input stream is not closed by this method.
-
def
transfer(in: File, out: OutputStream): Unit
Copies the contents of the input file
into theoutstream.Copies the contents of the input file
into theoutstream. The output stream is not closed by this method. -
def
transfer(in: File, out: File): Unit
Copies the contents of
intoout. -
def
transferAndClose(in: InputStream, out: OutputStream): Unit
Copies all bytes from the given input stream to the given output stream.
Copies all bytes from the given input stream to the given output stream. The input stream is closed after the method completes.
- def unzip(from: File, toDirectory: File, filter: NameFilter = AllPassFilter, preserveLastModified: Boolean = true): Set[File]
- def unzipStream(from: InputStream, toDirectory: File, filter: NameFilter = AllPassFilter, preserveLastModified: Boolean = true): Set[File]
- def unzipURL(from: URL, toDirectory: File, filter: NameFilter = AllPassFilter, preserveLastModified: Boolean = true): Set[File]
- def urlAsFile(url: URL): Option[File]
- val utf8: Charset
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
def
withTemporaryDirectory[T](action: (File) ⇒ T): T
Overload of
withTemporaryDirectorywithkeepDirectoryset to false. -
def
withTemporaryDirectory[T](action: (File) ⇒ T, keepDirectory: Boolean): T
Creates a temporary directory and provides its location to the given function.
Creates a temporary directory and provides its location to the given function. The directory is deleted after the function returns if
keepDirectoryis set to false. -
def
withTemporaryFile[T](prefix: String, postfix: String)(action: (File) ⇒ T): T
Overload of
withTemporaryFilewithkeepFileset to false. -
def
withTemporaryFile[T](prefix: String, postfix: String, keepFile: Boolean)(action: (File) ⇒ T): T
Creates a file in the default temporary directory, calls
actionwith the file, deletes the file ifkeepFileis set to true, and returns the result of callingaction.Creates a file in the default temporary directory, calls
actionwith the file, deletes the file ifkeepFileis set to true, and returns the result of callingaction. The name of the file will begin withprefix, which must be at least three characters long, and end withpostfix, which has no minimum length. -
def
write(properties: Properties, label: String, to: File): Unit
Writes
propertiesto the Fileto, usinglabelas the comment on the first line.Writes
propertiesto the Fileto, usinglabelas the comment on the first line. If any parent directories oftodo not exist, they are first created. -
def
write(file: File, bytes: Array[Byte]): Unit
Writes
bytestofile, overwriting any existing content.Writes
bytestofile, overwriting any existing content. If any parent directories do not exist, they are first created. -
def
write(file: File, content: String, charset: Charset = defaultCharset, append: Boolean = false): Unit
Writes
contenttofileusingcharsetor UTF-8 ifcharsetis not explicitly specified.Writes
contenttofileusingcharsetor UTF-8 ifcharsetis not explicitly specified. Ifappendisfalse, the existing contents offileare overwritten. Ifappendistrue, the newcontentis appended to the existing contents. Iffileor any parent directories do not exist, they are created. -
def
writeLines(writer: PrintWriter, lines: Seq[String]): Unit
Writes
linestowriterusingwriter'sprintlnmethod. -
def
writeLines(file: File, lines: Seq[String], charset: Charset = defaultCharset, append: Boolean = false): Unit
Writes
linestofileusing the givencharsetor UTF-8 ifcharsetis not explicitly specified.Writes
linestofileusing the givencharsetor UTF-8 ifcharsetis not explicitly specified. Ifappendisfalse, the contents of the file are overwritten. Ifappendistrue, the lines are appended to the file. A newline is written after each line and NOT before the first line. If any parent directories offiledo not exist, they are first created. - def writer[T](file: File, content: String, charset: Charset, append: Boolean = false)(f: (BufferedWriter) ⇒ T): T
-
def
zip(sources: Traversable[(File, String)], outputZip: File): Unit
Creates a zip file.
Creates a zip file.
- sources
The files to include in the zip file paired with the entry name in the zip. Only the pairs explicitly listed are included.
- outputZip
The file to write the zip to.