拷贝assets资源目录下xml文件到sdcard

private void copyXmlToProgram() {
        File confData = new File(PathUtils.getExternalStoragePath() + "/program", "conf.xml");
        AssetManager assetManager = getAssets();
        InputStream input = null;
        try {
            input = assetManager.open("conf.xml");
            InputStreamReader inputReader = new InputStreamReader(input, "UTF-8");
            BufferedReader bReader = new BufferedReader(inputReader);
            FileWriter fw = new FileWriter(confData);
            String line = "";
            while ((line = bReader.readLine()) != null) {
                fw.write(line);
            }
            fw.close();
            input.close();
            inputReader.close();
            bReader.close();
        } catch (IOException e) {
            LogUtils.e("preset==open==conf=====fail");
        }
    }

注意 此方法比较耗时需放在子线程调用

你可能感兴趣的:(xml,java)