I have a text file with a strange encoding "UCS-2 Little Endian" that I want to read its contents using Java.

As you can see from the screenshot above, the contents of the file are displayed fine in Notepad ++, but when I read it using this code, only garbage is printed in the console:
String textFilePath = "c:\strange_file_encoding.txt" BufferedReader reader = new BufferedReader( new InputStreamReader( new FileInputStream( filePath ), "UTF8" ) ); String line = ""; while ( ( line = reader.readLine() ) != null ) { System.out.println( line );
The main thing is that the user selects the file to read, so it can be of any encoding, and since I cannot find the encoding of the file, I decode it using "UTF8", but, as in the above example, he cannot read it correctly.
Is it possible to read such strange files correctly? Or at least I can determine if my code can read it correctly?
source share