Given that course.txt is accessible and contains:

Course::Java

and given the code fragment:

public static void main(String[] args){
    int i;
    char c;
    try (FileInputStream fis = new FileInputStream("course.txt");
            InputStreamReader isr = new InputStreamReader(fis);) {
        while (isr.ready()) { //line n1
            isr.skip(2);
            i = isr.read();
            c = (char) i;
            System.out.print(c);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

What is the result?

A. ur :: va
B. ueJa
C. The program prints nothing.
D. A compilation error occurs at line n1.

题解

用「*」来表示目前文件指针的位置。

Course::Java
*

第 11 行 while 循环条件式成立。运行第 12 行,指针往后跳两格。

Course::Java
  *

运行第 13 行,读取到「u」之后,指针往后跳一格。

Course::Java
   *

运行第 15 行,输出「u」。接着回到程序第 11 行,while 循环条件式成立,会运行第 12 行,指针往后跳两格。

Course::Java
     *

运行第 13 行,读取到「e」之后,指针往后跳一格。

Course::Java
      *

运行第 15 行,输出「e」。接着回到程序第 11 行,while 循环条件式成立,会运行第 12 行,指针往后跳两格。

Course::Java
        *

运行第 13 行,读取到「J」之后,指针往后跳一格。

Course::Java
         *

运行第 15 行,输出「J」。接着回到程序第 11 行,while 循环条件式成立,会运行第 12 行,指针往后跳两格。

Course::Java
           *

运行第 13 行,读取到「a」之后,指针往后跳一格。

Course::Java
            *

运行第 15 行,输出「a」。接着回到程序第 11 行,已经读取到文件结尾,所以 while 循环条件式不成立,跳出 while 循环。