[问题]请问关于文件读取行的问题!!!

楼主: SST2000 (BMW 428i)   2020-01-24 03:02:00
我有一个文件*.txt档里面内容是这样
In this below-sea-level basin, steady drought and record summer heat make
Death Valley a
land of extremes. Yet, each extreme has a striking contrast. Towering peaks
are frosted with
winter snow. Rare rainstorms bring vast fields of wildflowers. Lush oases
harbor tiny fish
and refuge for wildlife and humans. Despite its morbid name, a great
diversity of life survives
in Death Valley.
在程式码里面用
while(bufferedReader.readLine() != null)
{
System.out.println(bufferedReader.readLine());
}
结果只会显示第二行和第四行
land of extremes. Yet, each extreme has a striking contrast. Towering peaks
are frosted with
and refuge for wildlife and humans. Despite its morbid name, a great
diversity of life survives
但是如果用
String str = null;
while((str=bufferedReader.readLine()) != null)
{
System.out.println(str);
}
就可以显示文件全部的内容,但是请问这两种方式在逻辑上好像
没什么不一样????请问为什么会有这样的状况?
作者: vavamos (vavamos)   2020-01-24 03:18:00
看一下你哪边有用到readLine方法 用debug模式查就知道了
作者: dennisxkimo (Dennis(一上B就糟糕))   2020-01-24 05:49:00
例1:while读 print读 while读 print 读 所以只有双数行印出例2:while读进str print已读进str (loop)就会每行印出

Links booklink

Contact Us: admin [ a t ] ucptt.com