How to get the path to the Android assets folder in the application package

前端 未结 3 1503
渐次进展
渐次进展 2020-12-31 00:37

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

相关标签:
3条回答
  • 2020-12-31 01:14

    Could you move the folder to your /raw folder? Then you could use:

     com.your.package:raw/yourFile
    

    Like this:

    int resourceId = context.getResources().getIdentifier("com.your.package:raw/somefile.txt");
    File f = new File(context.getResources().openRawResource(resourceId));
    

    And here's someone doing it with the assets folder:

    Android Assets with sub folders

      InputStream is = getAssets().open("subfolder/somefile.txt");
    
    0 讨论(0)
  • 2020-12-31 01:20

    Use file:///android_asset for accessing the asset folder and then you can always give your subfolder there.

    AssetManager assetManager = null;   // null ???  Get the AssetManager here.
            AssetFileDescriptor assetFileDescriptor = null;
            try{
               assetFileDescriptor = assetManager.openFd("file:///android_asset/yourfolder/file");
                    FileDescriptor fd = assetFileDescriptor.getFileDescriptor();
           } catch (Exception e){}
    
    0 讨论(0)
  • 2020-12-31 01:30
    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);
    
    0 讨论(0)
提交回复
热议问题