I am developing a new feature for my android app to enable data backup and restore. I am using XML files to backup data. This is a piece of code that sets encoding for an ou
FileReader and other readers don't detect encoding. They just use the platform default encoding which can be UTF-8 by coincidence. It has no relation to the actual encoding of the file.
You cannot detect XML file encoding until you read it enough to see the encoding attribute.
From getInputEncoding() documentation
if inputEncoding is null and the parser supports the encoding detection feature, it must return the detected encoding
And:
If setInput(Reader) was called, null is returned.
So it appears that pre 11 doesn't support detection which is enabled by using setInput(is, null). I don't know how you are getting "UTF-8" when using setInput(reader) as the documentation says it should return null.
Then:
After first call to next if XML declaration was present this method will return encoding declared.
So in pre 11, you could try calling .next() intially before calling .getInputEncoding