WriteFile - Maple Help

FileTools[Text]

 WriteString
 write a string to a file
 WriteFile
 write a string to a file and close the file

 Calling Sequence WriteString(file, str) WriteFile(file, str)

Parameters

 file - file descriptor or filename str - Maple string to be printed

Description

 • The WriteString(file, str) and WriteFile(file, str) commands write the specified Maple string to the specified file.
 • Both commands return a count of the number of characters written.  Due to different character encodings, this number may differ from the number of bytes written to disk.
 • If file is default, the output is written to the current output stream.
 • If file is terminal, the line is written to the top level output stream. The top level output stream is the current output stream that was in effect when Maple was started.
 • WriteString does not close the file after writing the specified string. To ensure all data is appended to file it is necessary to explicitly close the file after WriteString or other FileTools[Text] commands are performed.
 • WriteFile behaves identically to WriteString, except that if the specified file was not already open prior to WriteFile being called, then WriteFile will close it before it returns. WriteFile therefore offers a convenient syntax to write a string to disk with a single command, without the need to open or close the file explicitly.

Examples

 > $\mathrm{FileTools}\left[\mathrm{Text}\right]\left[\mathrm{WriteString}\right]\left("testfile","This\nis\na\ntest"\right)$
 ${14}$ (1)
 > $\mathrm{FileTools}\left[\mathrm{Text}\right]\left[\mathrm{Close}\right]\left("testfile"\right)$
 > $\mathrm{FileTools}\left[\mathrm{Text}\right]\left[\mathrm{ReadLine}\right]\left("testfile"\right)$
 ${"This"}$ (2)
 > $\mathrm{FileTools}\left[\mathrm{Text}\right]\left[\mathrm{ReadLine}\right]\left("testfile"\right)$
 ${"is"}$ (3)
 > $\mathrm{FileTools}\left[\mathrm{Text}\right]\left[\mathrm{ReadLine}\right]\left("testfile"\right)$
 ${"a"}$ (4)
 > $\mathrm{FileTools}\left[\mathrm{Text}\right]\left[\mathrm{ReadLine}\right]\left("testfile"\right)$
 ${"test"}$ (5)
 > $\mathrm{FileTools}\left[\mathrm{Remove}\right]\left("testfile"\right)$
 > $\mathrm{FileTools}\left[\mathrm{Text}\right]\left[\mathrm{WriteFile}\right]\left("testfile","This is another test."\right)$
 ${21}$ (6)
 > $\mathrm{FileTools}\left[\mathrm{Remove}\right]\left("testfile"\right)$

Compatibility

 • The FileTools[Text][WriteFile] command was introduced in Maple 18.