Monday, May 4, 2015

Reading from a file

static void ReadTextFile(Args _args)
{
    TextIo file;
    FileName filename = @"c:\TEMP\customers.txt";
    container con;
    FileIoPermission permission;
    #File
   
    try
    {
        //permission = new FileIoPermission(filename, #io_read);
        //permission.assert();
       
        file = new TextIo(filename, #io_read);
        if (!file)
            throw Exception::Error;
       
        file.inRecordDelimiter(#delimiterCRLF);
        file.inFieldDelimiter(";");
        info("AccountNum - name - InvoiceAccount - CustGroup");
        con = file.read();
        while (file.status() == IO_Status::Ok)
        {
            info(strfmt("%1 - %2 - %3 - %4",
            conpeek(con,1),
            conpeek(con,2),
            conpeek(con,3),
            conpeek(con,4)));
            con = file.read();
        }
    }
    catch(Exception::Error)
    {
        error("Access to Read the file "+filename);
    }
   // CodeAccessPermission::revertAssert();
}

No comments:

Post a Comment