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/<package_name> on the internal storage, and then being used. I get the code, but what I do not get is, what is the need to copy the assets to internal storage?
Right-click on the asset in the Navigation Panel and choose Copy, or choose Copy from the More menu. Enter a New Page Name for the copied asset.
Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. Step 3 – Create a new Assets folder and write a new text file in it.
Assets provide a way to include arbitrary files like text, xml, fonts, music, and video in your application. If you try to include these files as "resources", Android will process them into its resource system and you will not be able to get the raw data.
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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With