Read UTF-8 Encoded Data in java

In this post, we will see how to read UTF-8 Encoded Data.

Sometimes, we have to deal with UTF-8 Encoded Data in our application. It may be due localization or may be processing data from user input.

There are multiple ways to read UTF-8 Encoded Data in Java.

Using Files’s newBufferedReader()

We can use java.nio.file.Files's newBufferedReader() to read UTF8 data to String.

Output:

यह फ़ाइल UTF-8 newBufferWriter से लिखी गई है

Please note that WriteUTF8newBufferWriter.txt was written from this example.

Using BufferedReader

We need to pass encoding as UTF8 while creating new InputStreamReader.

Output:

UTF-8 Demo for java2blog.com
यह हिंदी का वाक्य है

Please note that UTFDemo.txt was written from this example.

Using DataInputStream’s readUTF() method

We can use DataInputStream readUTF() to read UTF8 data to file.

आप कैसे हैं

Please note that WriteUTFDemo.txt was written from this example.

That’s all about how to write UTF-8 Encoded Data in java

Was this post helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *