'FileReader - readAsText encoding both utf-8 and ANSI

I'm using the API readAsText for getting the content from file with french characters

encoding = "UTF-8"
reader.readAsText(e.target.files.item(0), encoding)

The files could be encoding by UTF-8 or ANSI, in this case it is not working for ANSI file while reading UTF-8 and also not working for UTF-8 file while reading ANSI file.

I've tried ISO-8859-1, ISO-8859-3, ISO-8859-4, CP1251, latin1, none of them work for both.

So is there a way to read both utf-8 and ANSI, or whith encoding I should use for french file ? thanks for help



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source