File Input Output (original) (raw)
Published on 10 September 2018 (Updated: 10 May 2025)
Welcome to the File Input Output page! Here, you'll find a description of the project as well as a list of sample programs written in various languages.
This article was written by:
- Jeremy Grifski
Description
Most languages have built-in utilities or functions for reading and writing files. Many of these input/output functions follow a similar pattern across programming languages: a string to the path of the file and a "mode". A mode is how the files is opened. Will the file be opened for reading, writing, or even both? Will the file be appending new content? Truncated?
Requirements
In general, a File IO solution should perform the following:
- Write some arbitrary content to a file (use
output.txt
) - Read back that content and print it to the user
More specifically, begin with writing a file to disk. In the write function, you should show how to open a file with write abilities and write some contents to the file. Before closing the file, you should ensure everything is written to disk. Then, close the file. There should be basic error checking to confirm file opening was successful.
With the read file function, open the file with read abilities. Most higher level languages offer a way to read line by line or even transfer the whole contents into a string. One way to read the file is to loop line by line and do some processing. Printing each line to the screen is enough. Like in the write function, make sure there is some basic error checking.
Testing
Verify that the actual output matches the expected output (see Requirements).
Articles
There are 33 articles:
- File Input Output in Algol68
- File Input Output in Awk
- File Input Output in Bash
- File Input Output in Beef
- File Input Output in C
- File Input Output in C#
- File Input Output in C++
- File Input Output in Commodore Basic
- File Input Output in Dg
- File Input Output in Elvish
- File Input Output in Euphoria
- File Input Output in Gnu Make
- File Input Output in Go
- File Input Output in Haskell
- File Input Output in Java
- File Input Output in Javascript
- File Input Output in Julia
- File Input Output in Kotlin
- File Input Output in Lua
- File Input Output in Mathematica
- File Input Output in Objective C
- File Input Output in Octave
- File Input Output in Odin
- File Input Output in Perl
- File Input Output in Php
- File Input Output in Powershell
- File Input Output in Python
- File Input Output in R
- File Input Output in Ruby
- File Input Output in Rust
- File Input Output in Scala
- File Input Output in Typescript
- File Input Output in Wren