How to skip N bytes while reading a file char by char using FileInputStream() in Java

1 Answer

0 votes
package javaapplication1;

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

public class JavaApplication1 {

    public static void main(String[] args) {

        File file = new File("d://data.txt");
        int ch;

        try {
            StringBuilder sb = new StringBuilder("");
            try (FileInputStream fis = new FileInputStream(file)) {
                fis.skip(5);
                while ((ch = fis.read()) != -1) {
                    sb.append((char) ch);
                }
                System.out.println(sb);
            }

        } catch (IOException ioe) {
            System.out.println(ioe);
        }
    }
}

/*
      
run:

c c++ c# php
  
 */

 



answered Nov 12, 2016 by avibootz

Related questions

1 answer 165 views
1 answer 193 views
1 answer 259 views
1 answer 187 views
1 answer 213 views
...