File Access Block

The File Access block allows you to read and write data to and from files on your EV3 Brick.
Choose the File Name and Mode
File Name
Mode Selector
Input
Output
The following three steps are needed to use the File Access block:

1. Write data to the file.
2. Close the file.
3. Read the file.

These steps may be set up in blocks right after each other or placed throughout your program.

Once files are created, they can be accessed either through the File Access block or the Memory Browser.
Modes
Read


The Read mode sends the data in the text file to the output. You can use the Mode Selector to choose whether the output must be Text or Numeric.

While numbers can be read as Text, if you try and read Text as numbers, the EV3 Brick will behave unexpectedly.

You cannot Read from a file until that file has been closed. See the Close mode below for more information.
Write


The Write mode copies text to write data and writes it to the file. If the file does not exist, this block will create a file.

Writing to an existing file will add data to the end of the file. Writing will not erase any pre-existing data.

To re-write a file, first use the Delete mode to delete the file, then use the Write mode to create a new data file.
Delete


The Delete mode permanently deletes the named file.
Close


The Close mode closes the file named.

You must close a file after you have finished writing to it in order to Read it.
Example
This program writes three ambient light measurements, taken at 5-second intervals, into the “light” file. A comma is used to separate the numbers. The program then closes the file.

The contents of the “light” file are read, then displayed on the EV3 Brick Display. The program waits for 30 seconds before ending so that the Display is not cleared immediately.
Inputs and Outputs
The input of the File Access block provides the data that is to be written to the file. You can enter the input data directly into the block. Alternatively, the data can be supplied by Data Wires from the output of other Programming Blocks.
InputTypeNotes
Text to Write TextThe text or number to be written to the file
The outputs of the File Access Block give the data that has been read from the file.
OutputTypeNotes
Numeric NumericOutputs the text from the file as a numeric value
Text TextOutputs the text from the file as text
File Access
Quick links