I receive sometime some remarks concerning how to use the TextIO file, so there is a little example of how to use it.
You must also know that TextIO class will replace the old AsciiIO class.
When you create your file with the 'new', you can also add a parameter: 'CodePage'. This CodePage can create a file of type ANSI or UTF8. For more information concerning this, read this page: http://msdn.microsoft.com/en-us/library/aa881745(v=ax.50).aspx
For other information on TextIO class: http://msdn.microsoft.com/en-us/library/aa603840(v=AX.50).aspx
So now, little example:
Write
public void writeOnFile(FileName _fileName, str _value, container _valueList) { #File TextIO file; // SET PERMISSION new FileIOPermission(_fileName, #io_write).assert(); // CREATE FILE file = new TextIO(_fileName, #io_write);
// CHECK STATUS if (!file || file.status() != IO_Status::Ok) { throw error('Can not create file'); } // ADD SIMPLY DATA file.write(_value); // ADD DATA SEPARATE BY ';' (For CSV file f.e.) file.outFieldDelimiter(';'); file.write(_valueList); // CLOSE FILE file = null; // REVERT ACCESS CodeAccessPermission::revertAssert();}
Read
private void readFile(FileName _fileName){ #File TextIO file; container line;
// SET PERMISSION new FileIOPermission(_fileName, #io_read).assert(); // SET FILE file = new TextIO(_fileName, #io_read); // CHECK STATUS if (!file || file.status() != IO_Status::Ok) { throw error("Can't open file"); } // SET DELIMITER FOR READ file.inFieldDelimiter(';'); // READ FIRST LINE line = file.read(); while (conLen(line)) { // Put your specific code here
// READ NEXT LINE line = file.read(); } // CLOSE FILE file = null; // REVERT ACCESS CodeAccessPermission::revertAssert();}
Disclaimer:
This programming example is for illustration purposes only. Microsoft disclaims all warranties and conditions with regard to use of the programming example for other purposes. Microsoft shall not, at any time, be liable for any special, direct, indirect or consequential damages, whether in an action of contract, negligence or other action arising out of or in connection with the use or performance of the programming example. Nothing herein should be construed as constituting any kind of warranty.