Как прочитать файл в Java с определенной кодировкой символов?

Я пытаюсь прочитать файл в формате UTF-8 или Windows-1252 в зависимости от вывода этого метода:

public Charset getCorrectCharsetToApply() {
    // Returns a Charset for either UTF-8 or Windows-1252.
}

Пока что у меня есть:

String fileName = getFileNameToReadFromUserInput();
InputStream is = new ByteArrayInputStream(fileName.getBytes());
InputStreamReader isr = new InputStreamReader(is, getCorrectCharsetToApply());
BufferedReader buffReader = new BufferedReader(isr);

Проблема, с которой я сталкиваюсь, заключается вBufferedReader экземпляр дляFileReader.

Более того:

The name of the file itself (fileName) cannot be trusted to be a particular Charset; sometime the file name will contain UTF-8 characters, and sometimes Windows-1252. Same goes for the file's content (however if file name and file content will always have matching charsets). Only the logic inside getCorrectCharsetToApply() can select the charset to apply, so attempting to read a file by its name prior to calling this method could very well result with, Java trying to read the file name with the wrong encoding...which causes it to die!

Заранее спасибо!

Ответы на вопрос(3)

Ваш ответ на вопрос