Showing posts with label File Handling. Show all posts
Showing posts with label File Handling. Show all posts

Tuesday, 4 December 2012

TableDataFrom_File

static void TableDataFrom_File(Args _args)

{

commaIO commaIO;

container readLine;

Tab2 k;

FileIOPermission fio;

FileName nameOfTheFile = “c:\\anil.txt”; //csv

;

if (winapi::fileExists(nameOfTheFile) == false)

throw error(strfmt(“file %1 not found”, nameOfTheFile) );

fio = new FileIOPermission(nameOfTheFile, ‘r’);

// read – r, write – w, append – a

fio.assert(); // demand

commaIO = new commaIO(nameOfTheFile,’r');

commaIO.inFieldDelimiter(‘,’); // \t – tab, | // outFieldDelimiter commaIo.inRecordDelimiter(‘\r\n’); // OutRecorDelimiter – read line by line

ttsbegin;

if(commaIO)

{

while(commaIO.status() == IO_status::Ok)

{

readLine = commaIO.read(); //writeExp

if (conlen(readLine) > 1) // check whether there are values in the next line {

k.Address = conpeek(readLine,1); k.DName = conpeek(readLine, 2); k.insert();

}

}

}

ttscommit;

CodeAccessPermission::revertAssert();

}

File Handling in DAX 2012

Writing to a Text File

static void textFileWrite(Args _args)

{

TextBuffer tb = new TextBuffer();

;

tb.appendText(“Hello World!”);

tb.appendText(“\nWelcome to MIT”);

tb.appendText(“\nHyderabad”);

tb.toFile(“c:\\Sample.txt”);

}

Reading from a Text File

static void textFileRead(Args _args)

{

TextBuffer tb = new TextBuffer();

;

if(WinApi::fileExists(“c:\\Sample.txt”))

{

tb.fromFile(“c:\\Sample.txt”);

info(tb.getText());

}

else

{

info(“No file exists”);

}

}