I have a whole folder structure that I want to copy from my assets folder. However, the mContext.getAssets().open() seems to only want a filename so that it can return an InputStream, which is only suitable for copying a single file. What I need is a File made from the folder in my assets folder so that I can recurse through all the files and folders and copy them all.
Does anybody know how to get the path to the assets folder so that I can create a File object?
Edit: After some study it appears that you can't access files in the assets/ and raw/ folders with absolute paths to be able to create a File object. It probably has to do with the encryption of the app package. I hope someone can prove me wrong though!
Final edit: I ended up creating an array of strings to hold the extra asset files:
private static final String[] DEFAULT_ALBUM_FILES =
{INTRO_TO_FLASHUM_DIR+"03 Never Can Say Goodbye.m4a",
INTRO_TO_FLASHUM_DIR+"11 Bossa Baroque.m4a",
INTRO_TO_FLASHUM_DIR+"intro fling.3gp"};
I then iterated through this copying each file individually using the mContext.getAssets().open() to get the InputStream. I don't think it is currently possible to iterate through a folder in the assets using normal File operations.
Step 2: Go to the app > right-click > New > Folder > Asset Folder and create the asset folder.
File > New > folder > assets Folder Two ways: Select app/main folder, Right click and select New => Folder => Asset Folder.
Place your text file in the /assets directory under the Android project and use AssetManager class as follows to access it.
AssetManager am = con.getAssets();//u have get assets path from this code
InputStream inputStream = null;
inputStream = am.open("file.xml");
or
String file_name="ur.xml"
inputStream = am.open("foldername/"+ur);
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