我遇到了最随机的问题。简单地说,我希望在 while 循环中进行迭代,直到满足某个条件,而当它显然不满足时,应该运行循环之后的代码。由于某种原因,while循环之后的代码没有运行......这是我的代码:
while (true)
{
Socket ClientSocketConnection = serverSocket.accept();
System.err.println("We have established a connection with a client!");
System.out.println(" ");
ServerInput = new BufferedReader(new InputStreamReader(ClientSocketConnection.getInputStream()));
ServerOutput = new DataOutputStream(ClientSocketConnection.getOutputStream());
while((StringInput = ServerInput.read()) != -1)
{
//Things get done here
}
//methodBeingUsed is a string here
switch (methodBeingUsed){
case "GET":
GET();
break;
case "POST":
POST(sBuffer.toString());
break;
}
System.err.println("The Connection will now Terminated!");
ServerOutput.close();
ServerInput.close();
ClientSocketConnection.close();
}
}
基本上switch语句由于某种原因没有运行?当我调试代码时,我从ServerInput
变量中得到最后一个-1,代码就停止了。停止并且不继续while(true)
循环中的其他所有内容。真的不知道为什么会这样......