Can BufferedReader continue to read line in text file when pass to another function?

空扰寡人 提交于 2019-12-06 14:02:27

A BufferedReader object is self-contained (thanks to Java's heavy emphasis on Object Orientation), so you are free to pass it between functions and inside loops, and it will retain it's state - including the read line.

However, if you are trying to call a method to process the line you have just read, then it would be much more efficient to pass the line itself to the method as a String, instead of passing the entire BufferedReader object.

while( myBufferedReader.ready() ) {
    String line = myBufferedReader.readLine();
    processLine( line );
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!