Skip n bytes while reading the file using FileInputStream - Java File Path IO

Java examples for File Path IO:FileInputStream

Description

Skip n bytes while reading the file using FileInputStream

Demo Code


import java.io.*;
 
public class Main {
 
  public static void main(String[] args) {
    File file = new File("C://Folder//ReadString.txt");
   /*from   w w  w  . j a  v  a 2 s  .  c  o  m*/
    try
    {
       FileInputStream fin = new FileInputStream(file);
       int ch;
       //skip first 10 bytes
       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);
    }
  }
}

Result


Related Tutorials