我在程序中有一个while循环,只有当某个条件成立时才会执行某些操作,但在此之前它不会执行任何操作。每次运行循环时,我都会在控制台上打印“运行”一词,但这不再必要。当我删除system.out.println时,循环立即关闭并停止工作。为什么会发生?Java while循环只适用于打印
int INFINITE = 1;
try {
S3Object object = s3.getObject(new GetObjectRequest("saucyMMO", "logins.txt"));
while (INFINITE == 1) {
System.out.println();
if (tryToLogin == true) {
INFINITE = 0;
BufferedReader br = new BufferedReader(
new InputStreamReader(object.getObjectContent()));
String lineValue = null;
while((lineValue = br.readLine()) != null && loggedInAs == null) {
String splitResult[] = lineValue.split(",");
boolean retVal = splitResult[0].equals(ui.usernameLogin.getText());
boolean retVal2 = splitResult[1].equals(ui.passwordLogin.getText());
if (retVal == true && retVal2 == true) {
loggedInAs = splitResult[0];
System.out.println("logged in as : " + loggedInAs);
} else if (retVal && !retVal2){
System.out.println("User exists, but password is incorrect");
} else {
}
}
}
}
} catch (AmazonServiceException ase) {
} catch (AmazonClientException ace) {
} catch (IOException e) {
e.printStackTrace();
}
我在异常处理AmazonServiceException和AmazonClientException添加,但我收到任何错误使用或不使用的System.out.println。
你怎么知道它存在循环? – w4etwetewtwet
您正在捕获catch块中的异常。这是一个**可怕的**想法。 – jahroy
......特别是如果你的程序不符合你的期望。 –