See the question and answer here ... Android: How to create a directory on an SD card and copy files from / res / raw?
EDIT : reflecting on this, I use the / assets folder, not / res / raw. This is roughly what I am doing ...
First get a valid folder on your external storage (usually an SD card) ...
File myFilesDir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/com.mycompany.myApp/files");
Replace com.mycompany.myApp on the path above with your application package name.
Then the following will copy all the files from the folder with the file names starting with "xyz", for example, xyz123.txt, xyz456.xml, etc.
try { AssetManager am = getAssets(); String[] list = am.list(""); for (String s:list) { if (s.startsWith("xyz")) { Log.d(TAG, "Copying asset file " + s); InputStream inStream = am.open(s); int size = inStream.available(); byte[] buffer = new byte[size]; inStream.read(buffer); inStream.close(); FileOutputStream fos = new FileOutputStream(myFilesDir + "/" + s); fos.write(buffer); fos.close(); } } } catch (Exception e) {
Please note that you will need the following permission in the AndroidManifest.xml ...
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
source share