问题
I have this function to read text file with BufferedReader. I want to know if I can called another function and pass the readline/continue to read text file. If it can pass, can it loop the same function?
回答1:
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 );
}
来源:https://stackoverflow.com/questions/10629269/can-bufferedreader-continue-to-read-line-in-text-file-when-pass-to-another-funct