See also the Piping and redirection page.

Redirect from stdin

$ > file.txt

From a command.

$ echo 'My text' > file.txt

$ my_command > file.txt

If you use redirection with no input, you need to type or paste text. Then use a terminating character - CTRL+D

$ > file.txt
My text
^D
$ cat file.txt
My text

Write an empty file

This is not so well known. Using a colon signifies empty input.

$ : > file.txt

More widely-known:

$ echo '' > file.txt