See the question and answer here...Android: How to create a directory on the SD Card and copy files from /res/raw to it??
EDIT: Thinking about it, I use the /assets folder and not /res/raw. This is roughly what I do...
First get a valid folder on your external storage (normally SD card)...
File myFilesDir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/com.mycompany.myApp/files");
Replace com.mycompany.myApp
in the path above with your app's package name.
Then the following will copy all files from the assets folder with filenames beginning with "xyz", e.g., 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) {
// Better to handle specific exceptions such as IOException etc
// as this is just a catch-all
}
Note you'll need the following permission in the AndroidManifest.xml file...
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />