2009年2月18日 星期三

第156題

Place the code fragments into position to use a BufferedReader to read in an entire text file.
class PrintFile{
public static void main(String[] args){
BufferedReader buffReader = null; /
//More code here to initialize buffReader
try{
String temp;
while( Place here Place here ){
System.out.println(temp);
}
}catch Place here
e.printStackTrace();
}
}
}

Code Fragments
(temp = buffReader.readLine())
&& buffReader.hasNext()
(temp = buffReader.nextLine())
(IOException e){
!= null
(FileNotFoundException e){

答案:
class PrintFile{
public static void main(String[] args){
BufferedReader buffReader = null; /
//More code here to initialize buffReader
try{
String temp;
while( (temp = buffReader.readLine()) != null ){
System.out.println(temp);
}
}catch (IOException e){
e.printStackTrace();
}
}
}
參考:10-5-1 BufferedReader與BufferedWriter類別

------------------------------------

BufferedReader 是屬於 IO

沒有留言:

張貼留言