How to read text file in Java with user-defined charset

How to read text file in Java with charset (encoding) UTF-8 using InputStreamReader.

Which character set Character streams use? This depends on your operating system and it's locale. If you know in which encoding (charset) is your file, you can use InputStreamReader, in which you will define file encoding (charset).

try (BufferedReader reader = new BufferedReader(new InputStreamReader(
new FileInputStream("file.txt"), "UTF-8"))) {
String line = null;
while ((line = reader.readLine()) != null) {
} catch (IOException ex) {