title: Reading any text file having strange encoding?
body: <p>I have a text file with a strange encoding "UCS-2 Little Endian" that I want to read its contents using Java. </p>
  
  <p><img src="https://i.stack.imgur.com/V5hIX.jpg" alt="Opening the text file using NotePad++"></p>
  
  <p>As you can see in the above screenshot the file contents appear fine in Notepad++, but when i read it using this code, just garbage is being printed in the console:</p>
  
  <pre><code>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 );  // Prints garbage characters 
  }
  </code></pre>
  
  <p>The main point is that the user selects the file to read, so it can be of any encoding, and since I can't detect the file encoding I decode it using "UTF8" but as in the above example it fails to read it right.</p>
  
  <p><strong>Is there away to read such strange files in a right way ? Or at least can i detect if my code will fail to read it right ?</strong></p>