Java OCA OCP Practice Question 2579

Question

Consider the following snippet:

try (FileReader inputFile = new FileReader(file)) {
             //#1
             System.out.print( (char)ch );
     }
}

Which one of the following statements can be replaced in the place of statement #1?

  • a) while( (ch = inputFile.read()) != null) {
  • b) while( (ch = inputFile.read()) != -1) {
  • c) while( (ch = inputFile.read()) != 0) {
  • d) while( (ch = inputFile.read()) != EOF) {


b)

Note

The read() method returns -1 when the file reaches the end.




PreviousNext

Related