在使用真机调试数据库应用的时候,没有Root过的手机,没有办法经过文件浏览器查看手机里面的数据库。没有办法,只能将数据库复制到SD卡上面,而后再调试。代码以下:java
package com.mm.util; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.nio.channels.FileChannel; import android.content.Context; import android.util.Log; public class Database2SD { public static void copyDatabase2SD(Context context,String databaseName){ String fileName="/data/data/"+context.getPackageName()+"/databases/"+databaseName; File file=new File("/data/data/"+context.getPackageName()); for(String path:file.list()){ Log.e("Database2SD",path); } File databaseFile=new File(fileName); try { FileInputStream fis = new FileInputStream(databaseFile); FileChannel inChannel=fis.getChannel(); FileOutputStream fos=new FileOutputStream(new File("/sdcard/"+databaseName)); FileChannel outChannel=fos.getChannel(); outChannel.transferFrom(inChannel, 0, inChannel.size()); fis.close(); fos.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }