External Files

Read(1317) Label: external file,

This chapter lists code examples of handling external files, including Read/write a text file, Record log in a text file, Import a text file as a table sequence, and Store a table sequence as a text file.

Read/write a text file

 

A

 

1

=file("D:\\test.txt")

 

2

>A1.write("USA")

Write a string into the file

3

=A1.read()

Read and return the file as a string

 

Record log in a text file

 

A

 

1

=file("D:\\test.log")

 

2

>A1.write@a(string(now())+": Start getting data")

"@a" indicates appending strings at the end

 

Import a text file as a table sequence

 

A

 

1

=file("D:\\employee.txt")

 

2

=A1.import()

 

3

=A1.import@t()

The first row is used as field names

 

Store a table sequence as a text file

 

A

 

1

=demo.query("select EID,NAME,STATE, GENDER, BIRTHDAY,HIREDATE,DEPT, SALARY from EMPLOYEE")

 

2

=file("D:/employee.txt")

 

3

>A2.export(A1)

 

4

>A2.export@t(A1)

Set field names as the title