File Modes
- r – read mode (the default)
- w – write mode
- a – append mode
- r+ – update mode, all previous data is preserved
- w+– update mode, all previous data is erased
- a+ – append update mode, previous data is preserved, writing is only allowed at the end of file
File Functions
- file.open() – Open a file (Create a new file when write mode)
- file.open(filename, mode)
- Eg : file.open(“New_File”, “r”)
- returns nil if file not open, else file opened returns true
- file.open(filename, mode)
- file.remove() – Remove a file.
- file.remove(filename)
- Eg: file.remove(“New_File”)
- return nil (nothing)
- file.remove(filename)
- file.rename() – Rename the file.
- file.rename(oldname, newname)
- Eg: file.rename(“Old_File”, “New_File”)
- return true if success, false if error.
- file.rename(oldname, newname)
Create a New file
- file.open(“File_Name”, “Mode”)
File – Hello world Program
file.open("hello/world.txt", "w") file.writeline("Hello World!") file.close()
Next :
Previous :