0

I got a simple?! Problem that I can't solve...

I'm trying to access a File in the assets folder like this:

File file = new File("file:///android_asset/test/sample.pdf");

But the file is not available because this

System.out.println("#### "+file.exists());

returns false.

Now things are getting strange.. if im using the AssetsManager and debug that folder with

for(String asset : getAssets().list("test")) {
    System.out.println("### FOUND ASSET " +asset);
}

I'm getting a positive result. (The sample.pdf is displayed).

Can someone tell me what I'm doing wrong? I have no clue at all.

Jenson
  • 625
  • 3
  • 16
  • click this http://developer.android.com/reference/android/content/res/AssetManager.html#list(java.lang.String)... may be you have to check entire path `like test/sample.pdf` may be it will give desired result – bGorle Aug 01 '14 at 15:00
  • 1
    Assets are not literal files at runtime - you can use them in many file-like ways and for example get a FileInputStream from one, but you may well (?) not be able to create an actual File object wrapping one. Update: in fact you cannot, see the duplicate linked in the banner at the top of this page. – Chris Stratton Aug 01 '14 at 15:06
  • 1
    But if you can be content with a FileInputStream or even a FileDescriptor you do not need to make an actual file system copy. – Chris Stratton Aug 01 '14 at 15:12

1 Answers1

0

Try this: File file = new File("android_asset/test/sample.pdf");

0xPixelfrost
  • 10,244
  • 5
  • 39
  • 58