gpt4 book ai didi

java - BufferedReader 不读取整个在线 XML 文件

转载 作者:数据小太阳 更新时间:2023-10-29 01:59:44 24 4
gpt4 key购买 nike

public static void main(String[] args) throws MalformedURLException, IOException 
{
// TODO code application logic here
URL link1 = new URL("xmlFileHere");
InputStream xml = link1.openStream();
InputStreamReader reader = new InputStreamReader(xml);
BufferedReader reader1 = new BufferedReader(reader);
while(reader1.readLine()!= null)
{
System.out.println(reader1.readLine());
}

}

你好。如您所见,我的 BufferedReader 没有读取整个在线 XML 文件,我不知道为什么。知道为什么会这样吗?
谢谢。

最佳答案

while(reader1.readLine()!= null)   // reading here
{
System.out.println(reader1.readLine()); // and here
}

每次循环都会跳过一行...

做,

String line=null;
while((line=reader1.readLine())!= null) // reading here
{
System.out.println(line); // and displaying here
}

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

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