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 では簡単に書けます… new InputStreamReader(filePath, "UTF-8"); しかし、Asset フォルダーから取得しているので、それを行うことはできません (「UTF-8」を引数としてとらない assetManager.open() メソッドを使用する必要があります。
何か案は?:)
ご協力ありがとうございました。