Chapter 7 External Files

Read(322) 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.

7.1 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

7.2 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

 

7.3 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

 

7.4 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