如何将安卓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打开就可以看到表结构了