I sent to the emulated android device SD card using DDMS and I can even see these in DDMS. The file names are POS1.png
and POS2.png
. The sdcard path is /storage/sdcard/foldername
In my code I want to check if my file isFile() so i have written
String filepath = "/storage/sdcard/foldername/POS1.png";
File file = new File(filepath);
if (!file.isFile()){
//do something
}
else{
//do something else
}
The if condition is always returning true (i.e. file is not a file).
I think it may be a permission issue (the current permissions on the files are u=>rwx
, g=>rwx
) so I am trying to change the permission of the file from adb shell
:
- I launched my program in the emulator
- Opened cmd (on windows. path for adb is already set in environment)
- Typed the following codes
C:\> adb shell
root@generic:/ # su
Output: su
root@generic:/ # chmod -R 777 /storage/sdcard/foldername/
Output: chmod -R 777 /storage/sdcard/foldername/
root@generic:/ # ls -l /storage/sdcard/foldername/
The permissions still show the same. Even in the DDMS they're the same. I even restarted the device and eclipse, no change. I tried the following variations too:
root@generic:/ # chmod -R 777 /storage/sdcard/foldername/*
root@generic:/ # chmod -R 777 /storage/sdcard/foldername/*.png
root@generic:/ # chmod 777 /storage/sdcard/foldername/POS1.png
Using u+rwx
/ g+rwx
/ o+rwx
/ a+rwx
in place of 777
gives me a "Bad Mode" message
Thank you in advance for the help!
Edit: So I used the following code to check the exception:
try {
FileInputStream fis = null;
fis = new FileInputStream("/storage/sdcard/foldername/POS1.png");
} catch (IOException e) {
Log.e("openfile", "Exception:"+e.getMessage());
}
I got the message open failed: EACCES (Permission Denied)"