What is the result?

Given that myFile.txt contains:

First

Second

Third

And given:

import java.io.BufferedReader;

import java.io.FileReader;

import java.io.IOException;

public class ReadFile04 {

public static void main(String[] args) {

try (BufferedReader buffIn =

new BufferedReader(new FileReader(“D:\\faculty\\myfile.txt”))) {

String line = “”;

int count = 1;

buffIn.mark(1);

line = buffIn.readLine();

System.out.println(count + “: ” + line);

line = buffIn.readLine();

count++;

System.out.println(count + “: ” + line);

buffIn.reset();

line = buffIn.readLine();

count++;

System.out.println(count + “: ” + line);

} catch (IOException e) {

System.out.println(“IOException”);

}

}

}

What is the result?

Given that myFile.txt contains:

First

Second

Third

And given:

import java.io.BufferedReader;

import java.io.FileReader;

import java.io.IOException;

public class ReadFile04 {

public static void main(String[] args) {

try (BufferedReader buffIn =

new BufferedReader(new FileReader(“D:\\faculty\\myfile.txt”))) {

String line = “”;

int count = 1;

buffIn.mark(1);

line = buffIn.readLine();

System.out.println(count + “: ” + line);

line = buffIn.readLine();

count++;

System.out.println(count + “: ” + line);

buffIn.reset();

line = buffIn.readLine();

count++;

System.out.println(count + “: ” + line);

} catch (IOException e) {

System.out.println(“IOException”);

}

}

}

What is the result?

A.
1: First
2: Second
3: Third

B.
1 : First
2: Second
3: First

C.
1: First
2: First
3: First

D.
IOExcepton

E.
Compilation fails



Leave a Reply 4

Your email address will not be published. Required fields are marked *


Ray

Ray

Marks the present position in the stream. Subsequent calls to reset() will attempt to reposition the stream to this point.
Resets the stream to the most recent mark.

Jav

Jav

B is the answer

marvin

marvin

B is correct – but only if you take default initial capacity of BufferedReader (8192), smaller size (e.g. 10) would make mark invalid.