Skip to main content
Log in

Mojo module

file

Implements the file based methods.

These are Mojo built-ins, so you don't need to import them.

For example, here's how to read a file:

var  f = open("my_file.txt", "r")
print(f.read())
f.close()
var  f = open("my_file.txt", "r")
print(f.read())
f.close()

Or use a with statement to close the file automatically:

with open("my_file.txt", "r") as f:
print(f.read())
with open("my_file.txt", "r") as f:
print(f.read())

Structs

Functions

  • open: Opens the file specified by path using the mode provided, returning a FileHandle.