How to create a text file and Write/Append text into the file

// TextFile is File object
// OutStreamObj is OutStream object
// CR and LF are Char trype

TextFile.CREATE( ‘C:\TextOutput.txt’); // To Create
TextFile.CREATEOUTSTREAM(OutStreamObj);

OutStreamObj.WRITETEXT (’1st Line’); // To write into the created text file

OutStreamObj.WRITETEXT (’This is not the second line of text to be outputed but to concatenate with the first line’);

OutStreamObj.WRITETEXT(); // This command is to move to next line
OutStreamObj.WRITETEXT(’2nd Line’) ;

TextFile.Close; // To end the writing and write out to the file.

// To Append text at the end of text file

TextFile.TEXTMODE := TRUE;

TextFile.WRITEMODE := TRUE;

TextFile.OPEN(’C:\TextOutput.txt’);

TextFile.SEEK(TextFile.LEN);

TextFile.WRITE(’2nd Line end’);

TextFile.CLOSE;

 // To Append text in new line of text file

CR := 10;

LF := 13;

TextFile.TEXTMODE := TRUE;

TextFile.WRITEMODE := TRUE;

TextFile.OPEN(’C:\TextOutput.txt’);

TextFile.SEEK(TextFile.LEN);

TextFile.WRITE(CR);

//OR

TextFile.WRITE(LF);

TextFile.WRITE(’3rd Line’);

TextFile.CLOSE;

Tags:

2 Responses to “How to create a text file and Write/Append text into the file”

  1. World Of Online E-books Says:

    World Of Online E-books…

    […]Mohana’s Dynamics Blog » Blog Archive » How to create a text file and Write/Append text into the file[…]…

  2. Why should you head to College Says:

    Why should you head to College…

    […]Mohana’s Dynamics Blog » Blog Archive » How to create a text file and Write/Append text into the file[…]…

Leave a Reply

*
To prove you're a person (not a spam script), type the security text shown in the picture. Click here to regenerate some new text.
Click to hear an audio file of the anti-spam word