Skipping part of an InputStream when reading from it

You can do so using the method skip. You can call this method from any point where you are in the inputstream.

The following program skips half of the file, where the filename is supplied at command line.

public class Main {
   public static void main(String args[]) throws Exception {
      if (args.length != 1) {
         System.err.println("Usage: java Main <file.txt>");
      File file = new File(args[0]);
      BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
      int half = (int) file.length() / 2;
      int b;
      while ((b = > 0) {
         System.out.print((char) b);