Skip to content Skip to sidebar Skip to footer

Filenotfoundexception Only In Android App

How is it that I only get FileNotFoundException in an android application and when I read it from a normal Java application it finds the directory. I am using the same code exactly

Solution 1:

There is probably no C: drice on your android phone.

You can use for your external drive:

Environment.getExternalStorageDirectory() + /* file */;

Solution 2:

This is this in this part of your code:

FilerandomContactsFile=newFile(("C://test//randomcontacts.txt"));

C://test//randomcontacts.txt is not in unix path format.

If your developing for a phone/tablet you should use something like

/mnt/sdcard/test/randomcontacts.txt

or better:

File rootPath=Environment.getExternalStorageDirectory();
FilerandomContactsFile=newFile(rootPath.getPath()+"/test/randomcontacts.txt");

Post a Comment for "Filenotfoundexception Only In Android App"