Creating A Java.IO.File From Assets

Nathan Sokalski 4,121 Reputation points
2022-09-02T03:51:44.287+00:00

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.

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

1 answer

Sort by: Most helpful
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 36,231 Reputation points Microsoft Vendor
    2022-09-05T07:09:20.22+00:00

    Hello,

    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