In a file system, without reading the previous text we cannot directly access the specific index. Thus, Reading text from a file from the specific index is achieved by skipping all the previous characters of a specified index. To read text from an index n, we need to skip (n-1) bytes. Here, we will use FileInputStream class to read text from the file.
long skip(long n): Skips over and discards n bytes of data from the input stream.
Syntax:
public long skip(long n) throws IOException
Parameters: n — the number of bytes to be skipped.
Returns: The actual number of bytes skipped.
Throws: IOException
Java
import java.io.FileInputStream;
public class GFG {
public static void main(String args[])
{
try {
FileInputStream fin = new FileInputStream(
"C:\\Users\\ASPIRE\\Desktop\\java folder\\Demo.txt");
int i = 0;
fin.skip(7);
System.out.print("Printing text from index 8: ");
while ((i = fin.read()) != -1) {
System.out.print((char)i);
}
fin.close();
}
catch (Exception e) {
System.out.println(e);
}
}
}
|
Demo.txt file:

Output:

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!