如何将安卓asset的图片拷贝到sd卡
核心代码如下:
public void WriteToSD(){ if(!isExist()){ write(); } } private void write(){ InputStream inputStream; try { inputStream = this.getResources().getAssets().open(mFileName); File file = new File(filePath); if(!file.exists()){ file.mkdirs(); } FileOutputStream fileOutputStream = new FileOutputStream(filePath + "/"+mFileName); byte[] buffer = new byte[512]; int count = 0; while((count = inputStream.read(buffer)) > 0){ fileOutputStream.write(buffer, 0 ,count); } fileOutputStream.flush(); fileOutputStream.close(); inputStream.close(); System.out.println("success"); } catch (IOException e) { e.printStackTrace(); } } private boolean isExist(){ File file = new File(filePath + "/"+mFileName); if(file.exists()){ return true; }else{ return false; } }
如何将app的数据库导出到sd卡上
private void copyDatabase() { File file = new File("/data/data/com.pic.optimize/databases"); String[] array = file.list(); for(int i=0;i<array.length;i++) { Log.d("TAG","=====array[i]="+array[i]); } File f = new File("/data/data/com.pic.optimize/databases/record107994554.db"); String sdcardPath = Environment.getExternalStorageDirectory().getAbsolutePath(); File o = new File(sdcardPath+"/record107994554.db"); if(f.exists()) { FileChannel outF; try { outF = new FileOutputStream(o).getChannel(); new FileInputStream(f).getChannel().transferTo(0, f.length(),outF); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } Toast.makeText(mContext, "完成", Toast.LENGTH_SHORT).show(); } }
然后导入到电脑上用Navicat打开就可以看到表结构了
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦