- Home /
Open a file by path from assets folder in Android
Hi all! I am to read a file of a proprietary file format using a plugin written in c++. To do this I need to pass the path to a file, i have succesfully done this in windows but now i need to migrate and build an app for Android. So my question is, does unity offer any support for extrating a file from the assetsfolder and then access that file by path in Android
Cheers
Answer by Voxel-Busters · Sep 16, 2015 at 07:16 AM
Place your assets in Streaming Assets folder and access from Android.
From Android:
InputStream _inputStream = context.getAssets().open(CommonDefines.PROJECT_ASSETS_FOLDER + largeIconName);
//Here PROJECT_ASSETS_FOLDER is subpath under StreamingAssets folder. getAssets will point to in on Android.
From Unity:
string _filePath = "jar:file://" + Application.dataPath + "!/assets/" + filename;
//Read the note on Streaming assets page as the files will be compressed by default when you place in that folder.
Hope this should get you started!
Answer by shadyshrif · Jul 04, 2017 at 07:52 PM
I solved the problem after I added my files in this directory inside the projec Assets/StreamingAssets/
then I read it inside the code
#if UNITY_ANDROID
string path = "jar:file://" + Application.dataPath + "!/assets/alphabet.txt";
WWW wwwfile = new WWW(path);
while (!wwwfile.isDone) { }
var filepath = string.Format("{0}/{1}", Application.persistentDataPath, "alphabet.t");
File.WriteAllBytes(filepath, wwwfile.bytes);
StreamReader wr = new StreamReader(filepath);
string line;
while ((line = wr.ReadLine()) != null)
{
//your code
}
#endif
Your answer
Follow this Question
Related Questions
Error when using a NDK built Library which depend on another one in a Unity project 0 Answers
How to copy an asset to the file system? 0 Answers
multithreaded rendering on android breaks nativetexture update in plugin 0 Answers
Android Plugin: Load assets from APK, but have low-level access to AssetManager. 0 Answers
How do you determine the Android Architecture during runtime? 1 Answer