4 Answers
4

Hosts files were used on those old days to provide an easier way of referring to a host: instead of decorating numbers you could create an alias to it.

Things got bigger, hard to maintain, specially when changes were made: you would have to update the host file of each computer in your network and problems could arise while some computers were updated and others weren't.

So DNS appeared and made everything a lot easier. But no one was obliged to eliminate the host file. There was no common definition of where the DNS server would be located, nor protocols specifications on how to broadcast requests to find those DNS servers. So it was possible to use the host file to indicate where to look for a DNS server, and then letting the DNS server handle all other inquires, for example.

Hosts files can also be thought as a security measure: it's under the control of the system administrator of the computer, and so it's thought to be secure: the one who alters it should know what he is doing. And even in the case of the compromise of the DNS server, the hosts file would remain trustful.

There are two important reasons. One is provide any local overrides that should take precedence over DNS. The other is to 100% ensure the ability to resolve critical IP address mappings under conditions where the machine might not be able to reach a DNS server.

Historically, the hosts file predates DNS. Way back before DNS, everyone downloaded the latest hosts file from a central repository.

Assuming that you already read the wikipedia link. I'd say having a plain text file that you can use to point any domain to whatever IP you like is a lot more convenient than, say, adding records to a DNS server. Think of you as a developer trying to make a fancy application that fakes example.com (or any other domain). It's easier to edit your local hosts file and change the hostname so when you point your browser to a sub-domain it goes to your own application:

I'm sure there are some more obscure origins for the hosts file as most present day operating systems have one (*nix, BSD, Windows) however they are useful in situations where you need to override published (authoritative) DNS with a local record for testing, troubleshooting, or other similar tasks.