Hi, I'm trying to read a file on Android. This is my code:
var inputXml = Titanium.Filesystem.getFile('/sdcard/input.xml'); if(inputXml.exist) { alert("Yes"); } else { alert("No"); }Always show "No" Here is the adb shell output:
#cd /sdcard #ls input.xmlI've tried another way. This is the second code
var inputXml = Titanium.Filesystem.getFile(Titanium.Filesystem.externalStorageDirectory,'input.xml'); if(inputXml.exist) { alert("Yes"); } else { alert("No"); }Here is the output: The firse alert shows "file:///mnt/sdcard/com.myApp.testApp/input.xml" The second alert shows "No"
Here is the adb shell output:
#cd /mnt/sdcard/com.myApp.testApp/ #ls input.xmlI can't understand the reason... Someone could help me?
4 Answers
try:
var file = Titanium.Filesystem.getFile(Titanium.Filesystem.externalStorageDirectory, '../input.xml');externalStorageDirectory is your app's dir, e.g. sdcard/com.your.app/ --u
It doesn't work...always the same
Nobody can help me?
You need to use exists() instead of exist in this line:
if(inputXml.exists())
Your Answer
Think you can help? Login to answer this question!