4D v19

file.setText( )

Home

 
4D v19
file.setText( )

file.setText( )  


 

The file.setText( ) method writes text as the new contents of the file. 

If the file referenced in the File object does not exist on the disk, it is created by the method. When the file already exists on the disk, its prior contents are erased, except if it is already open, in which case, its contents are locked and an error is generated. 

In text, pass the text to write to the file. It can be a literal ("my text"), or a 4D text field or variable. 

In charSet, pass the character set to be used for writing the contents. You can pass a string containing the standard character set name (for example “ISO-8859-1” or “UTF-8”) or its MIBEnum ID (longint). For more information about the list of character sets supported by 4D, refer to the description of the CONVERT FROM TEXT command.  If a Byte Order Mark (BOM) exists for the character set, 4D inserts it into the file. If you do not specify a character set, by default 4D uses the "UTF-8" character set and a BOM. 

In breakMode, you can pass a longint indicating the processing to apply to end-of-line characters before saving them in the file. The following constants, found in the "System Documents" theme are available:

Constant Type Value Comment
Document unchanged Longint 0 No processing
Document with native format Longint 1 (Default) Line breaks are converted to the native format of the operating system: CR (carriage return) under OS X, CRLF (carriage return + line feed) under Windows
Document with CRLF Longint 2 Line breaks are converted to Windows format: CRLF (carriage return + line feed)
Document with CR Longint 3 Line breaks are converted to OS X format: CR (carriage return)
Document with LF Longint 4 Line breaks are converted to Unix format: LF (line feed)

By default, when you omit the breakMode parameter, line breaks are processed in native mode (1).

Example  

 $myFile:=File("C:\\Documents\\Hello.txt";fk platform path)
 $myFile.setText("Hello world")



See also 

file.getText( )

 
PROPERTIES 

Product: 4D
Theme: File and Folder

This command can be run in preemptive processes

 
PAGE CONTENTS 
 
HISTORY 

 
ARTICLE USAGE

4D Language Reference ( 4D v19)
4D Language Reference ( 4D v19.1)