Android读取asset目录的文件转File

来源:互联网 发布:辐射4阴影优化 编辑:程序博客网 时间:2024/06/06 06:29

直接调用writeBytesToFile:
writeBytesToFile(getActivity().getAssets().open("xxx文件名"),file);

public static void writeBytesToFile(InputStream is, File file) throws IOException{    FileOutputStream fos = null;    try {          byte[] data = new byte[2048];        int nbread = 0;        fos = new FileOutputStream(file);        while((nbread=is.read(data))>-1){            fos.write(data,0,nbread);                      }    }    catch (Exception ex) {        logger.error("Exception",ex);    }    finally{        if (fos!=null){            fos.close();        }    }}
0 0
原创粉丝点击