2012-04-23 20 views
2
private void copyMB() { 
    AssetManager assetManager = this.getResources().getAssets(); 
    String[] files = null; 
    try { 
     files = assetManager.list(assetDir); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
    for(int i=0; i<files.length; i++) { 
     InputStream in = null; 
     FileOutputStream fos; 
     try { 
      in = assetManager.open(assetDir+"/" + files[i]); 

      fos = openFileOutput(files[i], Context.MODE_PRIVATE); 
      copyFile(in, fos); 
      in.close(); 
      in = null; 
      fos.flush(); 
      fos.close(); 
      fos = null; 
     } catch(Exception e) { 
      e.printStackTrace(); 
     }  
    } 
} 
private void copyFile(InputStream in, OutputStream out) throws IOException { 

    byte[] buffer = new byte[1024]; 
    int read; 

    while((read = in.read(buffer)) != -1){ 
     out.write(buffer, 0, read); 
    } 
} 

私の問題は、åäöのようなUTF-8文字が見た目が奇妙な文字に置き換えられていることです。 InputStreamリーダーがUTF-8を使用していることを確認するにはどうすればよいですか?通常のJavaでは、簡単に書くことができます。新しいInputStreamReader(filePath、 "UTF-8");しかし、私は、私は(私は文句を言わないの引数として「UTF-8」を取るassetManager.open()メソッドを使用する必要があることを行うcanot資産フォルダからそれを取得していますので、。.txtアセットをAndroidのUTF-8としてassetManagerで読み込むにはどうすればよいですか?

任意のアイデア?:)

ありがとうございます。あなた自身が書いている

答えて

3

new InputStreamReader(in, "UTF-8"); 

は、UTF-8エンコーディングを使用して新しいストリームリーダーを作成します。 InputStreamを引数としてcopyFile()メソッドに入れてください。

+1

パーフェクト。それはそうです; P – matphi

関連する問題