SD卡#

加载文件()#

The loadfile(filename, buffer) method loads the named file. If the optional bytearray is None, then an empty file is created.

参数

描述

文件名

要读取的文件的名称。

缓冲

可选。 用于将文件读入的字节数组。

**返回:**包含文件数据的字节数组。

# Read the file into new bytearray.
b = brain.sdcard.loadfile('MyTextFile.txt')

是否插入()#

The is_inserted() method returns the status of the SD Card.

Returns: True if an SD card is inserted into the brain. False if it is not.

文件大小()#

The filesize(filename) method returns the size in bytes of the named file.

参数

描述

文件名

要检查的文件的名称。

**返回:**文件的大小(以字节为单位)。

保存文件()#

The savefile(filename, buffer) method saves a bytearray into a named file. If the optional bytearray is None, then an empty file is created.

参数

描述

文件名

要写入的文件的名称。

缓冲

可选。 要写入文件的字节数组。

**返回:**写入的字节数。

# Write the bytearray into a file.
brain.sdcard.savefile('MyTextFile.txt', bytearray("Hello "))

追加文件()#

The appendfile(filename, buffer) method appends a bytearray into a named file. Append is used to add more data to an existing file.

参数

描述

文件名

要写入的文件的名称。

缓冲

要写入文件的字节数组。

**返回:**写入的字节数。

# Append the bytearray into a file.
brain.sdcard.appendfile('MyTextFile.txt', bytearray("World "))

尺寸()#

The size(filename) method returns the size in bytes of the named file.

参数

描述

文件名

要检查的文件的名称。

**返回:**文件的大小(以字节为单位)。

存在()#

The exists(filename) method checks to see if the named file exists on the sd card.

参数

描述

文件名

要检查的文件的名称。

Returns: True if file exists. False if it does not exist.