user1973591
user1973591

Reputation:

How to convert a Unicode text file in ANSI format using Java

I have one Text File abc.txt which is in Unicode format. I want to convert this into ANSI format. How to do this.

I have done google and got the following , but Its very lengthy to understand.

Java- Converting from unicode to ANSI

Upvotes: 1

Views: 3084

Answers (1)

Anya Shenanigans
Anya Shenanigans

Reputation: 94584

At a wild guess, because you're using pywinauto, it means that the data you have is in the default win32 encoding format for unicode, which is to say, in UTF-16LE. There is no such thing as a file in unicode, the file is in an encoded representation of unicode.

To convert a file from UTF-16 to ASCII,you want to do:

unicode_data = open(filename).read().decode('utf-16le')
ascii = unicode_data.decode('ascii')

Upvotes: 1

Related Questions