Java 需要双重输入。为什么?
我正面临一个需要双重“进入”的问题,以便程序继续进行,有人能告诉我吗Java 需要双重输入。为什么?,java,sockets,Java,Sockets,我正面临一个需要双重“进入”的问题,以便程序继续进行,有人能告诉我吗 public void run() { try { out.write("Enter message to encrypt: \n"); out.flush(); while (true) { entry = in.readLine(); result = caesarCipher(entry);
public void run() {
try {
out.write("Enter message to encrypt: \n");
out.flush();
while (true) {
entry = in.readLine();
result = caesarCipher(entry);
out.write("The encrypted message is " + result);
out.write("\tType q to end else type another message to encrypt");
out.flush();
}
} catch (IOException e) {
System.out.println(e);
}
}
这在客户端结束了
public EncryptClient() throws IOException {
Socket cSock = new Socket("LocalHost", portNumber);
Reader iRead = new InputStreamReader(cSock.getInputStream());
input = new BufferedReader(iRead);
userTerminal = new BufferedReader(new InputStreamReader(System.in));
output = new OutputStreamWriter(cSock.getOutputStream());
while (true) {
String line = input.readLine();
System.out.println(line);
line = userTerminal.readLine();
if (line.equals("q")) {
break;
}
output.write(line + "\n");
output.flush();
}
}
当我的客户机类连接到服务器类时,我需要输入一条消息进行加密,但需要双输入来显示结果。有人能给我点化一下吗?ReadLine将停止对流量的控制
public void run() {
try {
out.write("Enter message to encrypt: \n");
out.flush();
while (true) {
entry = in.readLine();
result = caesarCipher(entry);
out.write("The encrypted message is " + result);
out.write("\tType q to end else type another message to encrypt");
out.flush();
}
} catch (IOException e) {
System.out.println(e);
}
}
在您的代码中,它们是两个readLine
.readLine()代码>//(行字符串被重写两次)重复。移除它。你会没事的