File on Android

You must Login before you can answer or comment on any questions.

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.xml
I'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.xml
I 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

You need to use exists() instead of exist in this line:

if(inputXml.exists())

— answered 2 years ago by Doug Handy
answer permalink
1 Comment
  • if I use exists() instead of exist I get an error:

    TypeError: Cannot find function exist in object [object TiFile]

    — commented 2 years ago by Libero Rignanese

Your Answer

Think you can help? Login to answer this question!