Android - Copy files from assets to /data/data folder

前端 未结 4 499
囚心锁ツ
囚心锁ツ 2020-12-16 00:48

I need to use some files in my app. They are kept in asset folder. I saw discussions on SO, where the files are being copied from asset folder, to /data/data/ on the interna

4条回答
  •  既然无缘
    2020-12-16 01:16

    public final String path = "/data/data/com.aliserver.shop/databases/";
    public final String Name = "store_db";
    
    public void _copydatabase() throws IOException {
    
            OutputStream myOutput = new FileOutputStream(path + Name);
            byte[] buffer = new byte[1024];
            int length;
            InputStream myInput = MyContext.getAssets().open("store_db");
            while ((length = myInput.read(buffer)) > 0) {
                myOutput.write(buffer, 0, length);
            }
            myInput.close();
            myOutput.flush();
            myOutput.close();
    
        }
    

提交回复
热议问题