Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reading unicode text from assets

Trying to read an utf-8 encoded file in android...

InputStreamReader reader = new InputStreamReader(assets.open("data.txt"), "UTF-8");
BufferedReader br = new BufferedReader(reader); 
String line;
//The line below throws an IOException!!
line = br.readLine();

What's wrong with this code?

like image 350
Hadi Avatar asked Sep 05 '10 23:09

Hadi


People also ask

What is a UNICODE text?

Unicode is a standard encoding system that is used to represent characters from almost all languages. Every Unicode character is encoded using a unique integer code point between 0 and 0x10FFFF . A Unicode string is a sequence of zero or more code points.

How do I check if a char is UNICODE?

Check the length of the string and size in bytes. If both are equal then it ASCII. If size in bytes is larger than length of the string, then it contains UNICODE characters.

What is UNICODE text vs text?

With TEXT encoding, you can use all the most common characters in the alphabet. With UNICODE encoding, you can use special characters, like chinese, arabic, emoticons, ...


1 Answers

It looks like you file is too big, you have to split it onto several files (1048576 bytes maximum for each) or find another way to reduce file size. Here is an article about similar problem http://androidgps.blogspot.com/2008/10/dealing-with-large-resources.html

like image 146
Konstantin Burov Avatar answered Sep 27 '22 21:09

Konstantin Burov