小编mat*_*phi的帖子

如何在 Android 中通过 assetManager 将 .txt 资源读取为 UTF-8?

private void copyMB() {\n    AssetManager assetManager = this.getResources().getAssets();\n    String[] files = null;\n    try {\n        files = assetManager.list(assetDir);\n    } catch (Exception e) {\n        e.printStackTrace();\n    }\n    for(int i=0; i<files.length; i++) {\n        InputStream in = null;\n        FileOutputStream fos;\n        try {\n            in = assetManager.open(assetDir+"/" + files[i]);\n\n            fos = openFileOutput(files[i], Context.MODE_PRIVATE);\n            copyFile(in, fos);\n            in.close();\n            in = null;\n            fos.flush();\n            fos.close();\n            fos = null;\n        } catch(Exception e) {\n            e.printStackTrace();\n        }       \n    }\n}\nprivate void copyFile(InputStream in, OutputStream out) throws IOException {\n\n    byte[] buffer = new byte[1024];\n    int read;\n\n …
Run Code Online (Sandbox Code Playgroud)

android

3
推荐指数
1
解决办法
3615
查看次数

标签 统计

android ×1