I don't think you can make that check in the general case. Mojibake can easily be valid UTF-8. And you can only specify that files should be read in a particular encoding - at least that's how it works with the java compiler plugin. I also think it's beside the point.