Creating A Java.IO.File From Assets

Nathan Sokalski 4,116 Reputation points

I need to create a Java.IO.File from a file in my Assets. I would also be able to achieve my task with an absolute path to the Assets file if that is easier. Several of the places I have found say that in order to do this I need to make a temporary copy of the file, but this seems like a lot of extra unnecessary effort, so if there is any way to avoid it, it would be my preference. Is there an easy way to create a Java.IO.File or get the absolute path? If not, what is the best way to make a temporary copy (I have never done much working directly with files)? Thanks.

A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,284 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 34,461 Reputation points Microsoft Vendor


    It's no possible to get the absolute path of a file from Assets, due to they are embedded into the APK.

    If you want to read files from Assets, please use AssetManager.

    You could refer to Using Android Assets to get more details.

    Best Regards,

    Alec Liu.

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments