Detect Encoding Format of Text TXT File using C# .NET or Java | Encoding Name CodePage Character Set

When loading a TXT file, I want to get the encoding format of TXT. Is there any way to do this。
Thanks

@lingengliang,

We have logged your requirement in our issue tracking system. Your ticket number is WORDSNET-20149. We will further look into the details of this requirement and will keep you updated on the status of the linked issue. Sorry for the inconvenience.

@lingengliang,

You can use FileFormatInfo Class to detect the encoding of text file. For example, please try using the following code. Hope, this helps.

FileFormatInfo fileFormatInfo = FileFormatUtil.DetectFileFormat("E:\\Temp\\input.txt");
Console.WriteLine(fileFormatInfo.Encoding.EncodingName);
Console.WriteLine(fileFormatInfo.Encoding.CodePage);