gpt4 book ai didi

java - 输出只给我一行

转载 作者:行者123 更新时间:2023-12-01 23:30:29 24 4
gpt4 key购买 nike

任何人都可以在这里为我指出正确的方向吗?我有一个方法应该读取文件并显示该文件中的数据。我只能让它显示一行。我知道这很简单,我忽略了,但我的大脑很糊涂,我只是不断地挖一个更大的洞。

public static String readFile(String file) {
String data = "";
if (!new java.io.File(file).exists()) {
return data;
}
File f = new File(file);
FileInputStream fStream = null;
BufferedInputStream bStream = null;
BufferedReader bReader = null;
StringBuffer buff = new StringBuffer();

try {
fStream = new FileInputStream(f);
bStream = new BufferedInputStream(fStream);
bReader = new BufferedReader(new InputStreamReader(bStream));
String line = "";

while (bStream.available() != 0) {
line = bReader.readLine();

if (line.length() > 0) {
if (line.contains("<br/>")) {
line = line.replaceAll("<br/>", " ");
String tempLine = "";
while ((tempLine.trim().length() < 1)
&& bStream.available() != 0) {
tempLine = bReader.readLine();
}
line = line + tempLine;
}
buff.append(line + "\n");

}
}

fStream.close();
bStream.close();
bReader.close();

} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return buff.toString();

}

最佳答案

String line = null;
while ((line = bReader.readLine())!=null)

关于java - 输出只给我一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19393474/

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