Skip n bytes while reading the file using FileInputStream


import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class Main {
  public static void main(String[] args) {
    File file = new File("C:/data.dat");
    try {
      FileInputStream fin = new FileInputStream(file);
      int ch;
      fin.skip(10);
      while ((ch = fin.read()) != -1){
        System.out.print((char) ch);
      }
    } catch (FileNotFoundException e) {
      System.out.println("File not found" + e);
    } catch (IOException ioe) {
      System.out.println("Exception while reading the file " + ioe);
    }
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.