This Java program demonstrates how to skip bytes and read the content of a file. The program performs the following steps:
If any exception is thrown during the execution of the program, it is caught and an appropriate error message is displayed. Overall, the program demonstrates how to skip bytes in a file and read its contents using FileInputStream in Java.
import java.io.*; public class Skipping_Byte { public static void main(String[] args) { File file = new File("file.txt"); try { FileInputStream fi = new FileInputStream(file); int ch; System.out.print("File's Content after 5 bytes is : "); //skipping 5 bytes to read the file fi.skip(5); while ((ch = fi.read()) != -1) { System.out.print((char) ch); } } catch (FileNotFoundException f) { System.out.println("FileNotFoundException : " + f.toString()); } catch (IOException i) { System.out.println("IOException : " + i.toString()); } catch (Exception e) { System.out.println("Exception: " + e.toString()); } } }
File's Content after 5 bytes is : is Java Programs
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions