我有一个包含以下输入的文件:
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 语句之后。
关于Java 文件不从头开始读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8252005/