I know that skip(long)
method of FileInputStream
skips bytes from the starting position of the file and places the file pointer. But If we want to skip only 20 characters in the middle of the file, and the remaining part of the file as to be read, what we should do?
You should use a BufferedReader
. Its skip
method skips characters and not bytes.
To skip 20
characters from an existing FileInputStream
:
BufferedReader reader = new BufferedReader(new InputStreamReader(fileInputStream));
// read what you want here
reader.skip(20);
// read the rest of the file after skipping