android中访问手机存储空间,android – 访问手机内部存储以推入SQLite数据库文件...
我正在使用Netbeans和java開發我的android應用程序.當我使用模擬器時,我可以通過訪問以下路徑,data / data / com.example.helloandroid / database來訪問File explorer并將SQLite數據庫插入設備內部存儲器
但是當我使用真實設備時,我無法訪問此位置以將SQLite文件推送到手機的內部存儲(位置).
有人可以幫我如何將文件添加到手機內部存儲.謝謝
解決方法:
我認為該設備沒有root權限,這就是你無法訪問它的原因.如果你想通過編程方式在你的應用程序中進行,那么它是可能的.如果有人知道的話請分享一下.
編輯:好的,首先,
1. copy your Database.db file in your projects assets folder.
2. now using code copy database file from /asset to device's internal storage
(data/data//database folder).
對于代碼下使用的復制文件,
try {
// Open your local db as the input stream
InputStream myInput = myContext.getAssets().open("your database file name");
// Path to the just created empty db
String outFileName = "/data/data//databases/";
OutputStream myOutput = new FileOutputStream(outFileName);
// 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);
}
// Close the streams
myOutput.flush();
myOutput.close();
myInput.close();
}
catch (Exception e)
{
Log.e("error", e.toString());
}
標簽:android
來源: https://codeday.me/bug/20190723/1515201.html
總結
以上是生活随笔為你收集整理的android中访问手机存储空间,android – 访问手机内部存储以推入SQLite数据库文件...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android拍照功能无预览,Andro
- 下一篇: android中白色怎么表示,通知栏图标