Java Program to Read Text From File From a Specified Index Last Updated : 05 Feb, 2021 Comments Improve Suggest changes Like Article Like Report 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 // Java program to read text from file from a specified // index import java.io.FileInputStream; public class GFG { public static void main(String args[]) { try { // attach the file to FileInputStream FileInputStream fin = new FileInputStream( "C:\\Users\\ASPIRE\\Desktop\\java folder\\Demo.txt"); int i = 0; // discards 7 bytes of data from the input // stream. fin.skip(7); // read from the file 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: Comment More infoAdvertise with us Next Article Java Program to Read Text From File From a Specified Index P poojavichare1810 Follow Improve Article Tags : Java Java Programs Java-Files Practice Tags : Java Similar Reads Java Program to Read a File to String There are multiple ways of writing and reading a text file. This is required while dealing with many applications. There are several ways to read a plain text file in Java e.g. you can use FileReader, BufferedReader or Scanner to read a text file. Given a text file, the task is to read the contents 8 min read Java Program to Find the Most Repeated Word in a Text File Map and Map.Entry interface will be used as the Map interface maps unique keys to values. A key is an object that is used to retrieve a value at a later date. The Map.Entry interface enables you to work with a map entry. Also, we will use the HashMap class to store items in "key/valueâ pairs and acc 3 min read Java Program to Read a Large Text File Line by Line As we are well verse with this topic let us put more stress in order to figure out minute differences between them. Here we are supposed to read from a file on the local directory where a text file is present say it be 'gfg.txt'. Let the content inside the file be as shown below: Geeks for Geeks. A 3 min read How to Read a File From the Classpath in Java? Reading a file from the classpath concept in Java is important for Java Developers to understand. It is important because it plays a crucial role in the context of Resource Loading within applications. In Java, we can read a file from the classpath by using the Input Stream class. By loading the cla 3 min read Java Program to Search for a File in a Directory Searching files in Java can be performed using the File class and FilenameFilter interface. The FilenameFilter interface is used to filter files from the list of files. This interface has a method boolean accept(File dir, String name) that is implemented to find the desired files from the list retur 3 min read Java Program to Search an Element in Vector A vector in Java is a dynamic array that can be resized as needed. It is synchronized, which means it is safe in multi-threaded programs. To find an element in a Vector we have to loop through its elements to find a match. In this article, we will learn how to search for a component in a Vector usin 3 min read Java Program to Read Content From One File and Write it into Another File File handling plays a major role in doing so as the first essential step is writing content to a file. For this is one must know how to write content in a file using the  FileWriter class. The secondary step is reading content from a file and print the same. For this, one must have good hands on Fil 5 min read Java Program to Implement the String Search Algorithm for Short Text Sizes Pattern searching is a crucial problem in computer science. When we do search for a string in notepad/word file or browser or database, pattern searching algorithms are used to show the search results. A typical problem statement would be-Given a text txt[0..n-1] and a pattern pat[0..m-1], write a f 4 min read How to Extract a Specific Line from a Multi-Line String in Java? In Java, String Plays an important role. As String stores or we can say it is a collection of characters. We want to get a specific line from a multi-line String in Java. This can also be done in Java. In this article, we will be learning how to extract a specific line from a multi-line String in Ja 2 min read How to Get the File's Parent Directory in Java? Java is one of the most popular and powerful programming languages. It is widely used for various purposes. In this article, we are going to learn how to find the parent directory of a file or a specified path. Methods to Get the Parent Directory of a fileIn Java, we can get the parent Directory wit 3 min read Like