进入手机内部存储,以推动在SQLite数据库文件 [英] Access the phone internal storage to push in SQLite database file

查看:125
本文介绍了进入手机内部存储,以推动在SQLite数据库文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发我使用NetBeans和Java的Andr​​oid应用程序。当我使用模拟器我可以访问的文件浏览器,并通过访问以下路径,数据/数据​​/ com.example.helloandroid /数据库

I am developing my android application using Netbeans and java. When I am using the emulator I can access the File explorer and insert an SQLite database in to device internal memory by accessing the following path, data/data/com.example.helloandroid/database

在我使用的是真正的设备,但我不能访问这个位置推SQLite的文件到手机的内部存储(位置)。

But I can not access this location to push the SQLite File in to the phone's internal storage (location) when I am using the real device.

有人可以帮我如何在文件中,以手机内部存储补充。谢谢

Can someone please help me how to add the file in to phones internal storage. Thanks

推荐答案

我认为该设备不具有超级用户权限,这就是为什么你不能访问它。如果你想在你的应用程序以编程则是可能的。如果有人知道更好,然后这个请与大家共享。

I think the device doesn't have root permission, that's why you can't access it. If you want to do in your app with programmatically then it is possible. If anybody knows better then this please share it.

编辑:确定,首先,

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).

有关复制文件使用以下code,

For copy file use below code,

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());
}

这篇关于进入手机内部存储,以推动在SQLite数据库文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆