This line looks suspect:
if (file.endsWith(".htm") | file.endsWith(".html")) {
The |
operator is the bitwise-OR operator. You need the logical-OR operator, ||
.
EDIT
Adding what @MadProgrammer suggessted in a comment:
Call toLowerCase()
on the filename to account for the possibility that the file ends in .HTM
or .HTML
.