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/<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性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...