private void CopyAssets2() {
AssetManager assetManager = getAssets();
String[] files = null;
try {
files = assetManager.list("");
} catch (IOException e) {
Log.e("File Error", e.getMessage());
}
for (String filename : files) {
InputStream in = null;
OutputStream out = null;
try {
in = assetManager.open(filename);
out = new FileOutputStream("/sdcard/Translate/" + filename);
copyFile2(in, out);
in.close();
in = null;
out.flush();
out.close();
out = null;
} catch (Exception e) {
Log.e("Save Error", e.getMessage());
}
}
}
private void copyFile2(InputStream in, OutputStream out)
throws IOException {
char[] buffer = new char[1024];
Reader reader = new BufferedReader( new InputStreamReader(in, "UTF-8"));
Writer writer = new BufferedWriter(new OutputStreamWriter(out, "UTF-8"));
int read;
while ((read = reader.read(buffer)) != -1) {
writer.write(buffer, 0, read);
}
reader.close();
writer.flush();
writer.close();
}
我使用assetManager 获取输入流,并将其作为指定UTF-8 编码的阅读器参数传递。我也在用 UTF-8 的 writer 写入输出流文件路径
文件被读写,但编码仍然错误。我得到这样的角色:在哪里...... =“D�nde est”/D�nde
我做错了什么?