本篇文章主要介绍了"Android 将assets中的文件拷贝到本地SD卡使用",主要涉及到方面的内容,对于HTMLjrs看球网直播吧_低调看直播体育app软件下载_低调看体育直播感兴趣的同学可以参考一下:
在项目中遇见要讲assets中的图片拷贝到本地的SD卡中,以备数据分析,之前找了很多都是都通“files:///assets/”加文件名的方式,读取。主要是读取...
在项目中遇见要讲assets中的图片拷贝到本地的SD卡中,以备数据分析,之前找了很多都是都通“files:///assets/”加文件名的方式,读取。主要是读取assets中的HTML页面,但是这个不能满足我的需求,现在将assets中的文件拷贝的本来数据库的方法分享如下:
/**
* 从assets目录中复制整个文件夹内容
* @param context Context 使用CopyFiles类的Activity
* @param oldPath String 原文件路径 如:/aa
* @param newPath String 复制后路径 如:xx:/bb/cc
*/publicstaticvoidcopyFilesFassets(Context context,String oldPath,String newPath) {
try {
String fileNames[] = context.getAssets().list(oldPath);//获取assets目录下的所有文件及目录名if (fileNames.length > 0) {//如果是目录
File file = new File(newPath);
file.mkdirs();//如果文件夹不存在,则递归for (String fileName : fileNames) {
copyFilesFassets(context,oldPath + "/" + fileName,newPath+"/"+fileName);
}
} else {//如果是文件
InputStream is = context.getAssets().open(oldPath);
FileOutputStream fos = new FileOutputStream(new File(newPath));
byte[] buffer = newbyte[1024];
int byteCount=0;
while((byteCount=is.read(buffer))!=-1) {//循环从输入流读取 buffer字节
fos.write(buffer, 0, byteCount);//将读取的输入流写入到输出流
}
fos.flush();//刷新缓冲区
is.close();
fos.close();
}
Log.i("copy", "success");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
//如果捕捉到错误则通知UI线程
Log.i("copy", "false");
}
}
这种方法主要是用于文件共享,方便共享使用
').addClass('pre-numbering').hide();
$(this).addClass('has-numbering').parent().append($numbering);
for (i = 1; i <= lines; i++) {
$numbering.append($('
').text(i));
};
$numbering.fadeIn(1700);
});
});
以上就介绍了Android 将assets中的文件拷贝到本地SD卡使用,包括了方面的内容,希望对HTMLjrs看球网直播吧_低调看直播体育app软件下载_低调看体育直播有兴趣的朋友有所帮助。
本文网址链接:http://www.codes51.com/article/detail_371581.html