Cannot find files - Android

I’m having trouble reading a file on android with FileReader and File. It’s just a plain text file but for some reason it keeps telling me that it cannot find my file.



[java]

File r = new File(“Custom/Test.txt”);

if(r.exists()){

System.out.println(“Found file.”);

} else {

System.out.println(“File not found.”);

}



r = new File(“assets/Custom/Test.txt”);

if(r.exists()){

System.out.println(“Found file.”);

} else {

System.out.println(“File not found.”);

}

[/java]



and the output is:



[java]

I/System.out( 4193): File not found.

I/System.out( 4193): File not found.

[/java]



However, when I run it on the computer (not android configuration) I get:



[java]

File not found.

Found file.

[/java]



I’m not sure why it can’t find any of my files on android. Unless these functions aren’t valid on android, if so how would I read a file from my assets?

@nyfinscyf said:
if so how would I read a file from my assets?

Use the assetManager?

@nehon the assetManager doesn’t load plain text files. When I use loadAsset it tells me there is no loader for that format.

you can register your own loader. then it will be able to load your file, even cache it and so on…



look at the BitmapFontLoader for example, fnt files are text files

http://code.google.com/p/jmonkeyengine/source/browse/trunk/engine/src/core-plugins/com/jme3/font/plugins/BitmapFontLoader.java



you can register your loader this way :

[java]

assetManager.registerLoader(yourLoaderClass, "yourExtension");

[/java]

@nehon I had not thought about the BitmapFontLoader… I implemented an AssetLoader and now it works on both PC and Android.



Thank you for the help nehon!



Now I just got to figure out how to save the file or even create a new one.