- Erlang Tutorial
- Erlang - Home
- Erlang - Overview
- Erlang - Environment
- Erlang - Basic Syntax
- Erlang - Shell
- Erlang - Data Types
- Erlang - Variables
- Erlang - Operators
- Erlang - Loops
- Erlang - Decision Making
- Erlang - Functions
- Erlang - Modules
- Erlang - Recursion
- Erlang - Numbers
- Erlang - Strings
- Erlang - Lists
- Erlang - File I/O
- Erlang - Atoms
- Erlang - Maps
- Erlang - Tuples
- Erlang - Records
- Erlang - Exceptions
- Erlang - Macros
- Erlang - Header Files
- Erlang - Preprocessors
- Erlang - Pattern Matching
- Erlang - Guards
- Erlang - BIFS
- Erlang - Binaries
- Erlang - Funs
- Erlang - Processes
- Erlang - Emails
- Erlang - Databases
- Erlang - Ports
- Erlang - Distributed Programming
- Erlang - OTP
- Erlang - Concurrency
- Erlang - Performance
- Erlang - Drivers
- Erlang - Web Programming
- Erlang Useful Resources
- Erlang - Quick Guide
- Erlang - Useful Resources
- Erlang - Discussion
Erlang - write
This method is used to write the contents to a file.
Syntax
write(FileHandler,text)
Parameters
FileHandler − This is the handle to a file. This handle is the one that would be returned when the file:openoperation is used.
Text − The text which needs to be added to the file.
Return Value
None
For example
-module(helloworld). -export([start/0]). start() -> {ok, Fd} = file:open("Newfile.txt", [write]), file:write(Fd,"New Line").
Output
Whenever the above code is run, the line “New Line” will be written to the file. Note that because the mode is set to write, if there were any previous contents to the file, they will be overwritten.
To append to the existing contents of the file, you need to change the mode to append as shown in the following program.
-module(helloworld). -export([start/0]). start() -> {ok, Fd} = file:open("Newfile.txt", [append]), file:write(Fd,"New Line").
erlang_file_input_output.htm
Advertisements