logo

abstract class

sys::File

sys::Obj
  sys::Resource
    sys::File

File is used to represent a Uri path to a file or directory.

Slots

create

abstract File create()

Create a file or directory represented by this Uri. If isDir() is false then create an empty file, or if the file already exists overwrite it to empty. If isDir() is true then create a directory, or if the directory already exists do nothing. This method will automatically create any parent directories. Throw IOErr on error. Return this.

createTemp

static File createTemp(Str prefix := def, Str suffix := def, File dir := def)

Create a temporary file which is guaranteed to be a new, empty file with a unique name. The file name will be generated using the specified prefix and suffix. If dir is non-null then it is used as the file's parent directory, otherwise the system's default temporary directory is used. If dir is specified it must be a directory on the local file system. See deleteOnExit if you wish to have the file automatically deleted on exit. Throw IOErr on error.

Examples:

File.createTemp("x", ".txt") -> `/tmp/x67392.txt`
File.createTemp.deleteOnExit -> `/tmp/fan5284.tmp`
delete

abstract Void delete()

Delete this file. If this file represents a directory, then recursively delete it. If the file does not exist, then no action is taken. Throw IOErr on error.

deleteOnExit

abstract File deleteOnExit()

Request that the file or directory represented by this File be deleted when the virtual machine exits. Long running applications should use this method will care since each file marked to delete will consume resources. Throw IOErr on error. Return this.

eachLine

Void eachLine(|Str| f)

Convenience for in.eachLine. The input stream is guaranteed to be closed.

equals

override Bool equals(Obj that)

File equality is based on the un-normalized Uri used to create the File.

hash

override Int hash()

Return uri.hash.

in

abstract InStream in(Int bufferSize := def)

Open a new buffered InStream used to read from this file. A bufferSize of null or zero will return an unbuffered input stream. Throw IOErr on error.

list

abstract File[] list()

List the files contained by this directory. If the directory is empty or this file doesn't represent a directory, then return an empty list.

make

static File make(Uri uri)

Make a File for the Uri which represents a file on the local file system. If creating a Uri to a directory, then the Uri must end in a trailing "/" slash - Uri.isDir() must return true. If the file exists and it doesn't match Uri.isDir() then IOErr is thrown. If the file doesn't exist, then it is assumed to to a directory based on Uri.isDir(). If the Uri has a relative path, then it is assumed to be relative to the current working directory.

modified

abstract DateTime modified

Get or set the time the file was last modified. Modify time is null if unknown.

normalize

abstract File normalize()

Normalize this file path to its canonical representation.

os

static File os(Str osPath)

Make a File for the specified operating system specific path on the local file system.

osPath

abstract Str osPath()

Get this File as an operating system specific path on the local system. If this File doesn't represent a path on the local file system then return null.

out

abstract OutStream out(Bool append := def, Int bufferSize := def)

Open a new buffered OutStream used to write to this file. If append is true, then we open the file to append to the end, otherwise it is opened as an empty file. A bufferSize of null or zero will return an unbuffered input stream. Throw IOErr on error.

parent

abstract File parent()

Get the parent directory of this file or null. Also see Uri.parent().

plus

abstract File plus(Uri path)

Make a new File instance by joining this file's Uri together with the specified path.

Example:

File.make(`a/b/`) + `c` -> File.make(`a/b/c`)
File.make(`a/b`) + `c` -> File.make(`a/c`)
readAllBuf

Buf readAllBuf()

Convenience for in.readAllBuf. The input stream is guaranteed to be closed.

readAllLines

Str[] readAllLines()

Convenience for in.readAllLines. The input stream is guaranteed to be closed.

readAllStr

Str readAllStr(Bool normalizeNewlines := def)

Convenience for in.readAllStr. The input stream is guaranteed to be closed.

readObj

Obj readObj(Str:Obj options := def)

Convenience for in.readObj The input stream is guaranteed to be closed.

readProps

Str:Str readProps()

Convenience for in.readProps(). The input stream is guaranteed to be closed.

sep

static Str sep

Return the platform's file path separator - typically a slash.

size

abstract Int size()

Return the size of the file in bytes otherwise null if a directory or unknown.

toStr

override Str toStr()

Return uri.toStr.

writeObj

Void writeObj(Obj obj, Str:Obj options := def)

Convenience for out.writeObj The output stream is guaranteed to be closed.

writeProps

Void writeProps(Str:Str props)

Convenience for out.writeProps(). The output stream is guaranteed to be closed.