while (calendar.getTime().before(TUpdEndTm)) { Date date = calendar.getTime();calendar.add(Calendar .DAY_OF_YEAR,amount: 1) ; TUpdTm = sdf.format(date) ; String dir = rootdir + "/" + TUpdTm; // 连接FTP Channelsftp connect = FtpUtil.connect(username, password, host, port);List<String> rootFilelists = FtpUtil.listFiles(connect, rootdir); if (!rootFilelists.isEmpty() && rootFilelists.contains(TUpdTm)) {} else{} 在这段代码中,TUpdTm会在while的循环中变成三个不同的值,如何能让只要有一个TUpdTm满足if条件就不进入else,反之三次不同值得TUpdTm都不满足if条件才进入else
时间: 2024-02-21 12:56:58 浏览: 62
您可以使用一个布尔变量来记录是否有任何一个TUpdTm满足了if条件。具体来说,您可以在while循环之前声明一个布尔变量,例如`boolean found = false;`。在每次循环中,如果TUpdTm满足if条件,就将found设为true,然后跳出while循环。如果while循环结束后found仍然为false,就说明三次不同值的TUpdTm都不满足if条件,此时进入else分支即可。以下是修改后的代码:
```
boolean found = false;
while (calendar.getTime().before(TUpdEndTm) && !found) {
Date date = calendar.getTime();
calendar.add(Calendar.DAY_OF_YEAR, amount: 1);
TUpdTm = sdf.format(date);
String dir = rootdir + "/" + TUpdTm;
// 连接FTP
Channelsftp connect = FtpUtil.connect(username, password, host, port);
List<String> rootFilelists = FtpUtil.listFiles(connect, rootdir);
if (!rootFilelists.isEmpty() && rootFilelists.contains(TUpdTm)) {
found = true;
}
}
if (found) {
// do something
} else {
// do something else
}
```
阅读全文