HTML chapters

Chapter 15 of 17

Input, Output and Files

Try this in our HTML Compiler →

Talking to the world

A useful program reads input (from the keyboard, a file, a network call, or another program) and produces output (to the screen, a file, or another network call). HTML provides simple helpers for the basic cases and powerful libraries for the rest.

<!-- HTML forms are the standard way to gather user input -->
<form action="/submit" method="post">
  <input name="msg">
  <button>Send</button>
</form>

Buffering and performance

Reading or writing one byte at a time is usually slow. HTML buffers I/O behind the scenes so that small reads and writes are batched into larger ones. When you need maximum performance — large log files, streaming uploads — drop down to the buffered or streaming APIs explicitly.

Closing resources

Files, sockets and database connections must be closed when you are done with them. Forgetting leaks operating-system resources and eventually crashes long-running programs. Use the language's built-in with / using / defer construct (it has a different name in each language) to guarantee cleanup happens.

Try it yourself

HTML Compiler
CSS (optional)
Output
Code runs in a sandboxed preview inside your browser — your code is saved locally for next time.