Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6958201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:06:34+00:00 2026-05-27T15:06:34+00:00

I need to know the string path to a file on assets folder, because

  • 0

I need to know the string path to a file on assets folder, because I’m using a map API that needs to receive a string path, and my maps must be stored on assets folder

This is the code i’m trying:

    MapView mapView = new MapView(this);
    mapView.setClickable(true);
    mapView.setBuiltInZoomControls(true);
    mapView.setMapFile("file:///android_asset/m1.map");
    setContentView(mapView);

Something is going wrong with "file:///android_asset/m1.map" because the map is not being loaded.

Which is the correct string path file to the file m1.map stored on my assets folder?

Thanks

EDIT for Dimitru: This code doesn’t works, it fails on is.read(buffer); with IOException

        try {
            InputStream is = getAssets().open("m1.map");
            int size = is.available();
            byte[] buffer = new byte[size];
            is.read(buffer);
            is.close();
            text = new String(buffer);
        } catch (IOException e) {throw new RuntimeException(e);}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:06:34+00:00Added an answer on May 27, 2026 at 3:06 pm

    AFAIK the files in the assets directory don’t get unpacked.
    Instead, they are read directly from the APK (ZIP) file.

    So, you really can’t make stuff that expects a file accept an asset ‘file’.

    Instead, you’ll have to extract the asset and write it to a seperate file, like Dumitru suggests:

      File f = new File(getCacheDir()+"/m1.map");
      if (!f.exists()) try {
    
        InputStream is = getAssets().open("m1.map");
        int size = is.available();
        byte[] buffer = new byte[size];
        is.read(buffer);
        is.close();
    
    
        FileOutputStream fos = new FileOutputStream(f);
        fos.write(buffer);
        fos.close();
      } catch (Exception e) { throw new RuntimeException(e); }
    
      mapView.setMapFile(f.getPath());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to determine if a user-supplied string is a valid file path (i.e.,
Possible Duplicate: Android - get path of resource I need to know the string
I need to know how i can make a string like hello to Hello
I need to know if a variable in Python is a string or a
I need to know how I can replace the last s from a string
I need to know if there's a way in PHP to echo a string
I'm doing some attribute parsing as a string, so I need to know how
I need to split the string result of the autocomplete plugin . I know
I need to store a double as a string. I know I can use
Greetings, Would like to know if we need to explicitly free the string allocated

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.