2013-10-12 54 views
1

我必須從txt文件中檢索一些數據,然後在我的應用程序中顯示這些數據。特殊字符Android(ø)

我的問題是,如果我在我的txt裏面有特殊字符'ø',這個不會顯示出來,'?'被顯示。

我會嘗試檢查數據,如

if(string.charAt(i) == 'ø') do sth 

string.replace('ø' , 'O') 

但他們都不是工作,我認爲Java不能識別字符都沒有。

你有什麼想法嗎?

感謝

編輯

這是我讀出的數據

String[] obj = getText(getActivity(), myTXT.txt").split("\n"); 

其中的getText是:

public String getText(Context c, String fileName){ 

    ByteArrayOutputStream outputStream = null; 
    try { 

     AssetManager am = c.getAssets(); 
     InputStream is = am.open(fileName); 

     outputStream = new ByteArrayOutputStream(); 
     byte buf[] = new byte[1024]; 
     int len; 
     while ((len = is.read(buf)) != -1){ 
      outputStream.write(buf,0,len); 
     } 
     outputStream.close(); 
     is.close(); 

    } catch (FileNotFoundException e) { 
     e.printStackTrace(); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 

    return outputStream.toString(); 
} 
+2

請顯示您用來從文件中讀取的代碼。 –

回答

0

這些字符必須爲UTF-8編碼,檢查你的文件,而它越來越sa ved是否它的incoding。創建一個InputStreamReader實例,該實例使用指定編碼的構造函數。

InputStreamReader r= new InputStreamReader(new FileInputStream(myFile),"UTF-8"); 
// read your contents here. 
r.close();