gpt4 book ai didi

android - 访问手机内部存储推送SQLite数据库文件

转载 作者:太空宇宙 更新时间:2023-11-03 12:01:04 25 4
gpt4 key购买 nike

我正在使用 Netbeans 和 java 开发我的 android 应用程序。当我使用模拟器时,我可以访问文件资源管理器并通过访问以下路径将 SQLite 数据库插入到设备内存中,data/data/com.example.helloandroid/database

但当我使用真实设备时,我无法访问此位置以将 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/<package name>/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/<your_app_package_name>/databases/<database_file_name>";

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 - 访问手机内部存储推送SQLite数据库文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7268908/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com