Options
All
  • Public
  • Public/Protected
  • All
Menu

Class TextFile

The TextFile object is used to read and write files in text mode.

When using TextFile.WriteOnly, you need to call commit when you’re done writing otherwise the operation will be aborted without effect.

To read and write files in binary mode, use BinaryFile instead.

Hierarchy

  • TextFile

Index

Constructors

constructor

  • Opens a text file in the given mode.

Properties

Readonly atEof

atEof: boolean

True if no more data can be read.

codec

codec: string

The text codec. The codec is used for reading and writing from and to the file, respectively. Common codecs are supported, for example: “UTF-8”, “UTF-16”, and “ISO 8859-1”.

Readonly filePath

filePath: string

The path of the file.

Static Readonly Append

Append: typeof Append

Static Readonly ReadOnly

ReadOnly: typeof ReadOnly

Static Readonly ReadWrite

ReadWrite: typeof ReadWrite

Static Readonly WriteOnly

WriteOnly: typeof WriteOnly

Methods

close

  • close(): void
  • Closes the file. It is recommended to always call this function as soon as you are finished with the file.

commit

  • commit(): void
  • Commits all written text to disk and closes the file. Should be called when writing to files in WriteOnly mode. Failing to call this function will result in cancelling the operation, unless safe writing to files is disabled.

readAll

  • readAll(): string
  • Reads all data from the file and returns it.

readLine

  • readLine(): string
  • Reads one line of text from the file and returns it. The returned string does not contain the newline characters.

truncate

  • truncate(): void
  • Truncates the file, that is, gives it the size of zero, removing all content.

write

  • write(text: string): void
  • Writes a string to the file.

writeLine

  • writeLine(text: string): void
  • Writes a string to the file and appends a newline character.

Generated using TypeDoc