f.write()

描述:

将字符串或序列写入文件。

语法:

f.write(s)

 

f.write(A)

将字符串序列A写入文件f中,每个成员占一行。

备注:

将字符串s或串序列A写入文件f中。默认为覆盖式写入,即把文件中内容清除后再写入。

参数:

f

文件对象。支持txtcsvbtxxls等格式的数据文件。

s

字符串或blob值。

A

字符串序列。

选项:

@a

追加写入文件,不覆盖。如果文件内容不为空,则回车追加新行。

@b

写成二进制文件,此时参数sblob值。

@w

换行符使用windows风格,即用\r\n,缺省由操作系统决定。

示例:

 

A

 

1

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

 

2

>A1.write("China")

tmp.txt中覆盖写入字符串China

3

>A1.write@a("Chinese")

使用@a选项,追加写入字符串Chinese

4

=["China","America","England "]

 

5

>A1.write(A4)

A4串序列写入文件:

6

>A1.write(string(now())+":start")

模拟用write@a 函数写日志:

7

>A1.write@a(string(now())+":end")

8

>A1.write@a(string(now())+":startPrint")

9

>A1.write@a(string(now())+":endPrint")

10

=file("D:/test.btx").read@b()

读取二进制文件,返回结果类型为blob值。

11

=file("D:/result.btx").write@b(A10)

以二进制格式生成result.btx

12

=file("D:/employee.txt").write@w(A4)

换行符使用windows风格,即用\r\n

相关概念:

f.read()