【问题标题】:Android java: how to use if-then-elseAndroid java:如何使用 if-then-else
【发布时间】:2015-05-28 17:24:21
【问题描述】:

我正在使用带有 ADT 插件的 eclipse,并且我正在开发一个我想在其中使用 if then 和 else 的应用程序。 我想做这个

if file.txt not exist
then do    
startDownload();
readFile();
else  delete file.txt

【问题讨论】:

  • 您想先阅读 Java 编程语言的基础知识吗?
  • 我不知道写不存在
  • 这不是 java 语法。
  • 这个是存在的,我怎么能把don'texist放出来

标签: java android eclipse if-statement


【解决方案1】:

这里有一些代码可以尝试:

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

}

【讨论】:

    【解决方案2】:

    您可以在 android 中将以下表达式用于“if-then-else”条件,

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-25
      • 2017-08-13
      • 1970-01-01
      • 2021-11-06
      相关资源
      最近更新 更多