FileReader.readAsText
takes into account the encoding of the file. In particular, since you have a file encoded in UTF-8, there may be several bytes per character. Reading it as text, UTF-8 reads as is, and you get your line.
FileReader.readAsBinaryString
, on the other hand, does exactly what it says. It reads the byte file by byte. It does not recognize multibyte characters, which, in particular, is good news for binary files (basically nothing but a text file). Since & pi; is a double-byte character, you get two separate bytes that make it up on your string.
This difference can be seen in many places. In particular, when the encoding is lost and you see characters like & # xe9; displayed as & # xc3; & # xa9 ;.
source share