TextFile Service
The TextFile
service allows you to read from and write into text files.
Related Declarations
TextFile.OpenMode
enum TextFile.OpenMode { ReadOnly, WriteOnly, ReadWrite, Append }
List of modes that a file may be opened in.
The OpenMode values can be combined with the bitwise or operator.
Available operations
Constructor
TextFile(filePath: string, openMode: OpenMode = TextFile.ReadOnly)
Opens the file at filePath
in the given mode and returns the object representing the file.
Note: The mode influences which of the operations listed below can actually be used on the file.
atEof
atEof(): boolean
Returns true
if no more data can be read from the file, false
otherwise.
close
close(): void
Closes the file. It is recommended to always call this function as soon as you are finished with the file, in order to keep the number of in-flight file descriptors as low as possible.
filePath
filePath(): string
The absolute path of the file represented by this object.
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.
setCodec
setCodec(codec: string): void
Sets the text codec to codec
. The supported codecs are the same as for QTextCodec
, for example: "UTF-8", "UTF-16", and "ISO 8859-1".
truncate
truncate(): void
Truncates the file, that is, gives it the size of zero, removing all content.
write
write(data: string): void
Writes data
into the file at the current position.
writeLine
writeLine(data: string): void
Writes data
into the file at the current position and appends the newline character(s).
© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.