gpt4 book ai didi

java - BufferedReader 不读取整个文本文件

转载 作者:行者123 更新时间:2023-12-03 22:52:41 26 4
gpt4 key购买 nike

                String str = "";
try {

BufferedReader br = new BufferedReader(new FileReader(file.getAbsolutePath()));
while (br.readLine() != null) {
str += br.readLine();
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

String replace = str.replace("HTTP Request: ", "")
.replace("Resource URL: ","")
.replace("Attribute\t\tDescription", "| Attribute | Type | Description |<P>|----|----|<P>")
.replace("Data Type | Max Length | Requirement |", "")
.replace("N/A", "Object")
.replace("String", "| String")
.replace("255 |", "")
.replace("Required", "**Required**")
.replace("Optional", "**Optional**")
.replace("Request Example <P>", "")
.replace("Response Example <P>", "Nothing");

PrintWriter pw = null;

BufferedReader 忽略前 3 行并读取/转换其余行。不确定是什么问题。我尝试过其他 StackOverflow 解决方案,但它们似乎都不起作用!

最佳答案

问题在这里:

while (br.readLine() != null)

您检查 br.readLine() 是否不为空的时间您已经阅读了该行。要解决此问题,您可以尝试以下操作:
String line = br.readLine();
while (line != null){
str +=line;
line = br.readLine();
}

关于java - BufferedReader 不读取整个文本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37821173/

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