Skip to content Skip to sidebar Skip to footer

Android Java: How To Use If-then-else

i'm using eclipse with ADT plugin, and i'm developing an app where i want to use if then and else. i want to do this if file.txt not exist then do startDownload(); readFile();

Solution 1:

Here is some code to try:

Filef=newFile(filePathString);
if(!f.exists() && !f.isDirectory()) { 
 startDownload();
 readFile();
} 
else { 
   try { 
      file.delete();
   } catch (Exception e) { 
      e.printStackTrace();
   }

}

Solution 2:

you can use below expressions for "if-then-else" condition in android,

booleanisValid=true;
(isValid?"your_if_value_whatever":"your_else_value");

Post a Comment for "Android Java: How To Use If-then-else"