InputStreamReader question
Posted: Sat Aug 22, 2020 1:44 pm
Given that the file test.txt contains : 12345678 What will the following code print when compiled and run?
public static void main(String[] args) throws Exception{
try(FileInputStream fis = new FileInputStream("c:\\temp\\test.txt");
InputStreamReader isr = new InputStreamReader(fis)){
while(isr.ready()){
isr.skip(1);
int i = isr.read();
char c = (char) i;
System.out.print(c);
} } }
Why does it print 2468 instead of 2 or something else?
public static void main(String[] args) throws Exception{
try(FileInputStream fis = new FileInputStream("c:\\temp\\test.txt");
InputStreamReader isr = new InputStreamReader(fis)){
while(isr.ready()){
isr.skip(1);
int i = isr.read();
char c = (char) i;
System.out.print(c);
} } }
Why does it print 2468 instead of 2 or something else?