gpt4 book ai didi

Java 文件不从头开始读取

转载 作者:行者123 更新时间:2023-12-01 17:33:55 24 4
gpt4 key购买 nike

我有一个包含以下输入的文件:

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com