如何從android手機中把自己的資料庫給COPY出來

來源:互聯網
上載者:User

標籤:android   io   ar   sp   檔案   資料   on   問題   bs   

============問題描述============


自己寫個APK,安裝在android手機,程式運行時會建立一個SQLITE的資料庫;
用eclipse,可以看到資料庫的位置,我把手機插入電腦,打USB串連後,卻不能在手機中找到資料庫檔案(APK絕對是安裝在SD卡上的),有人說要有ROOT的許可權。不知如何?,如果要寫一個程式來實現,請高手指點思想,列出相關重點函數,謝謝

============解決方案1============


自己的應用複製自己的資料庫,無需root,直接檔案複製就行,大概如下:
File f = new File("/data/data/應用的包名/databases/資料庫名"); //比如  "/data/data/com.hello/databases/test.db"
String sdcardPath = Environment.getExternalStorageDirectory().getAbsolutePath();
File o = new File(sdcardPath+"cp.db"); //sdcard上的目標地址
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(mainpage.this, "完成", Toast.LENGTH_SHORT).show();
}

如何從android手機中把自己的資料庫給COPY出來

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.