write a string to a file - Maple Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Programming : Input and Output : File Manipulation : FileTools : FileTools/Text/WriteString

FileTools[Text][WriteString] - write a string to a file

FileTools[Text][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.

• 

WriteFile behaves identically to WriteString, except that if the file is not open prior to calling WriteFile, it will be closed before returning.  Therefore,  WriteFile offers a convenient syntax to write a string to disk with a single command, without the need to open or close the file explicitly.

• 

If no strings are specified, only a newline is printed.

Examples

FileTools[Text]WriteStringtestfile,This is a test

14

(1)

FileTools[Text]Closetestfile

FileTools[Text]ReadLinetestfile

This

(2)

FileTools[Text]ReadLinetestfile

is

(3)

FileTools[Text]ReadLinetestfile

a

(4)

FileTools[Text]ReadLinetestfile

test

(5)

FileTools[Remove]testfile

FileTools[Text]WriteFiletestfile,This is another test.

FileTools[Remove]testfile

See Also

file, FileTools[Remove], FileTools[Text], FileTools[Text][Close], FileTools[Text][Open], FileTools[Text][ReadLine], FileTools[Text][ReadString], IO_errors


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam