Java 检查文件大小是否大于 0

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5280665/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 10:23:42  来源:igfitidea点击:

Java check if file size is larger than 0

javaandroidif-statementfilesize

提问by GFlam

Hi i'm trying to create an if statement that checks the size of a file here's what i have although it's not working.

嗨,我正在尝试创建一个 if 语句来检查文件的大小,尽管它不起作用,但这是我所拥有的。

File file = new File("/path/to/file.zip");
long fileSize = file.length();
if (!(fileSize > 0));{
Toast.makeText(MainMethod.this, "Equal to 0", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(MainMethod.this, "Greater than 0", Toast.LENGTH_LONG).show();
}

回答by Sanjay T. Sharma

You have a semicolon at the end of your IF statement which is causing the problem here.

您的 IF 语句末尾有一个分号,这是导致问题的原因。

回答by mFontenot

There is a semicolon at the end of your if statement. Also, you can simplify the code somewhat by doing the following:

if 语句的末尾有一个分号。此外,您可以通过执行以下操作来稍微简化代码:

  if (file.length() > 0) 
  System.out.println("File Greater than 0");
else 
  System.out.println("File LessThanEqual to 0");

Just my opinion

只是我的观点