我在我的 Android应用程序中使用sqlite数据库.我想将数据库下载到pc.任何人都可以告诉我该怎么做? 如果您的应用程序在模拟器中,您只需使用DDMS并打开/data/data/your.package.name/databases. 如果
如果您的移动应用程序.这是我将数据库复制到sdcard根文件夹的方法.
/** The name of the database file */ static final String DATABASE_NAME = "mydatabase.db"; static final String DATABASE_NAME_FULL = "/data/data/com.my.application/databases/" + DATABASE_NAME; public static boolean backUpDataBase(Context context){ boolean result = true; // Source path in the application database folder String appDbPath = DATABASE_NAME_FULL; // Destination Path to the sdcard app folder String sdFolder = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + DATABASE_NAME; InputStream myInput = null; OutputStream myOutput = null; try { //Open your local db as the input stream myInput = new FileInputStream(appDbPath); //Open the empty db as the output stream myOutput = new FileOutputStream(sdFolder); //transfer bytes from the inputfile to the outputfile byte[] buffer = new byte[1024]; int length; while ((length = myInput.read(buffer))>0){ myOutput.write(buffer, 0, length); } } catch (IOException e) { result = false; e.printStackTrace(); } finally { try { //Close the streams if(myOutput!=null){ myOutput.flush(); myOutput.close(); } if(myInput!=null){ myInput.close(); } } catch (IOException e) { } } return result; }
你需要在manifest.xml中使用它
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />