我有一个带有以下输入的文件:
ADD 1 2
SUB 2 1
MUL 2 3
DIV 4 2
QUIT
与这部分代码:
BufferedReader in = null;
String input = "";
in = new BufferedReader(fin);
while ((input = in.readLine()) != null)
{
String line = in.readLine();
System.out.println(line); // for me to see the output
out.println(line); // thats for my server
out.flush(); // for the server
}
但它仅显示:
MUL 2 3
DIV 4 2
null
最佳答案
尝试这个:
BufferedReader in = null;
String input = "";
in = new BufferedReader(fin);
while ((input = in.readLine()) != null)
{
System.out.println(input); // for me to see the output
out.println(input); // thats for my server
out.flush(); // for the server
}
您从文件中读取了两次输入,一次在while语句中,一次在while语句后。