Read file with Unicode

Put your problem here if it does not fit any of the other categories.

Read file with Unicode

Postby bnkhanh » Wed Jan 09, 2008 2:41 am

I want read file with Unicode, my languae is VietNamese so I used UTF-8.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. //--------------------//
  2.  
  3.            try{
  4.  
  5.                
  6.  
  7.                      FileInputStream fIn = openFileInput("file.txt");  
  8.  
  9.                          
  10.  
  11.                   // Read file with UTF-8
  12.  
  13.                   InputStreamReader isr = new InputStreamReader(fIn,"UTF-8");      
  14.  
  15.  
  16.  
  17.                   char[] inputBuffer = new char[255];            
  18.  
  19.                  
  20.  
  21.                
  22.  
  23.                   isr.read(inputBuffer);
  24.  
  25.                   String readString = new String(inputBuffer);        
  26.  
  27.                    
  28.  
  29.                      
  30.  
  31.                       // Load content file on ViewText
  32.  
  33.                   read.setText(readString);          
  34.  
  35.                  
  36.  
  37.        
  38.  
  39.                
  40.  
  41.             } catch (Exception e) {
  42.  
  43.                 Log.e(TAG, "Error on Inputstream");
  44.  
  45.                 showAlert("Warning", "Error Exception " + e.toString(), "ok", true);
  46.  
  47.             }
  48.  
  49.  
  50.  
  51. //----------------------------------//
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


But i generated some error i can't solve.

I have i text file with content: "Và tôi cũng yêu em"
=> result: "Và tôi cũng yêu em" --> good

but text file with content: "Những thấm đẫm "
=> result: You will see result on Next Image....
Tran Van Khanh
Da Nang Polytechnic College
bnkhanh
Freshman
Freshman
 
Posts: 5
Joined: Fri Dec 07, 2007 8:03 am
Location: Viet Nam

Top

Postby bnkhanh » Wed Jan 09, 2008 2:56 am

File content "Những thấm đẫm"
And result here:
Attachments
result2.jpg
result2.jpg (20.16 KiB) Viewed 5155 times
Tran Van Khanh
Da Nang Polytechnic College
bnkhanh
Freshman
Freshman
 
Posts: 5
Joined: Fri Dec 07, 2007 8:03 am
Location: Viet Nam

Postby plusminus » Wed Jan 09, 2008 4:49 pm

Hello ,

we've had an issue about indic 'special'-characters :src: here.

At least the DalvikVM does support unicode, the problem you met was due to the fact that the default OS image used by the emulator didn't include the font for displaying these languages. Chinese/Japanese fonts were included in the default OS image through.

The emulator is not (yet!) capable of displaying all unicode characters. :(
When you digg into the string-characters (toCharArray())with debugger you'll see that the chars were read properly.

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby bee » Wed Dec 03, 2008 9:30 am

I have had an G1 already.
But maybe it don't support Vietnamese and I can not read the content of Vietnamese website.
Please help !!!
bee
Freshman
Freshman
 
Posts: 2
Joined: Wed Dec 03, 2008 9:21 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot] and 16 guests