G
G
go2goj2019-12-12 16:04:13
Java
go2goj, 2019-12-12 16:04:13

Why does skip on new FileInputStream(FileDescriptor.in) not work?

Why does skip on new FileInputStream(FileDescriptor.in) not work? Although with System.in skip in similar code it works...

import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.IOException;

public class Soltuion {

  public static void main(String[] args) throws IOException {
    FileInputStream keyboardStream = new FileInputStream(FileDescriptor.in);
    System.out.print(keyboardStream.read() + " ");
    keyboardStream.skip(100);  // любой аргумент напиши - не сработает 
    System.out.print(keyboardStream.read() + " ");
    System.out.print(keyboardStream.read() + " ");

    // Ввод: 8
    // Вывод: 56 13 10 (всё считал, а не только 56 c ожиданием нового ввода)
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
gansm, 2019-12-12
@go2goj

Since the FileInputStream overrides the skip from the InputStream and calls the native skip. Wrap in BufferedInputStream

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question