I am trying to read files using FileReader and write them into a separate file.
These files are UTF-8 encoded, but unfortuantely some of them still contain a BOM.
The relevant code I tried is this:
private final String UTF8_BOM = "\uFEFF";
private String removeUTF8BOM(String s)
{
if (s.startsWith(UTF8_BOM))
{
s=s.replace(UTF8_BOM, "");
}
return s;
}
line=removeUTF8BOM(line);
But for some reason the BOM is not removed. Is there any other way I can do this with FileReader? I know that there is the BOMInputStream that should work, but I'd rather find a solution using FileReader.