Android读取asset目录的文件转File

直接调用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();
        }
    }
}

猜你喜欢

转载自blog.csdn.net/leansmall/article/details/80685917
今日推荐