static void ReadTextFile(Args _args)
{
TextIo file;
FileName filename = @"c:\temp\cars.txt";
CarTable carTable;
container con;
FileIoPermission permission;
#File
;
try
{
// Create the permission class
permission = new FileIoPermission(filename, #io_read);
// Ask for permission to write the file
permission.assert();
// Create the TextIo object
file = new TextIo(filename, #io_read);
if (!file)
throw Exception::Error;
// Note that we now use inDelimiters
// instead of outDelimiters as in the
// previous example
file.inRecordDelimiter(#delimiterCRLF);
file.inFieldDelimiter(";");
// Write the header info
info("CarId - CarBrand - Mileage - Model - ModelYear");
// Read the first record from the file
con = file.read();
// Loop as long as the file status is ok
while (file.status() == IO_Status::Ok)
{
// Write the content to the infolog
info(strfmt("%1 - %2 - %3 - %4 - %5",
conpeek(con,1),
conpeek(con,2),
conpeek(con,3),
conpeek(con,4),
conpeek(con,5)));
// Read the next record from the file
con = file.read();
}
}
catch(Exception::Error)
{
error("You do not have access to write the file to the
selected folder");
}
// Revert the access privileges
CodeAccessPermission::revertAssert();
}
{
TextIo file;
FileName filename = @"c:\temp\cars.txt";
CarTable carTable;
container con;
FileIoPermission permission;
#File
;
try
{
// Create the permission class
permission = new FileIoPermission(filename, #io_read);
// Ask for permission to write the file
permission.assert();
// Create the TextIo object
file = new TextIo(filename, #io_read);
if (!file)
throw Exception::Error;
// Note that we now use inDelimiters
// instead of outDelimiters as in the
// previous example
file.inRecordDelimiter(#delimiterCRLF);
file.inFieldDelimiter(";");
// Write the header info
info("CarId - CarBrand - Mileage - Model - ModelYear");
// Read the first record from the file
con = file.read();
// Loop as long as the file status is ok
while (file.status() == IO_Status::Ok)
{
// Write the content to the infolog
info(strfmt("%1 - %2 - %3 - %4 - %5",
conpeek(con,1),
conpeek(con,2),
conpeek(con,3),
conpeek(con,4),
conpeek(con,5)));
// Read the next record from the file
con = file.read();
}
}
catch(Exception::Error)
{
error("You do not have access to write the file to the
selected folder");
}
// Revert the access privileges
CodeAccessPermission::revertAssert();
}
No comments:
Post a Comment