您的位置:首页 > 移动开发 > Android开发

Android读取asset目录的文件转File

2016-12-16 16:00 1106 查看
直接调用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();
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android