Skip to content Skip to sidebar Skip to footer

Filenot Found Exception In Android

when i run this piece of code as normal java application in main it runs fine. but when i try to use the same code in onCreate in one of the activity it says file not found excepti

Solution 1:

Android is based on linux so things like "D:" should never work.

If the file is on sd card try this:

StringstrFile= Environment.getExternalStorageDirectory() + "/android/Suyesh.2DV106.Assignment3/southern_cities.txt";

At the end your path should be something like: "/mnt/sdcard/android/Suyesh.2DV106.Assignment3/southern_cities.txt"

Solution 2:

Have you tried to use:

Filefile=newFile(TheCityMap.class.getResource(/* name */));
BufferedReaderreader=newBufferedReader(newFileReader( file ));

or:

newBufferedReader(newInputStreamReader(FlowAp.class.getResourceAsStream(""/* name */)))

Solution 3:

if D is your external storage directory (sdcard or flash), use Enviroment.getExternalStorageDirectory()

Post a Comment for "Filenot Found Exception In Android"