How can i read a file from nth line onwards in java

How can i read a file from nth line onwards in java

Hi,

I need to read a file content from its nth line onwards till end. How can i implement it in java.

Regards, Chinnu

View Answers

January 4, 2011 at 5:55 PM

Hi Friend,

Try the following code:

import java.io.*;
import java.util.*;

public class ReadNthLineToEnd {
          public static void main(String[] args) {
              StringBuffer buffer=new StringBuffer();
                String line = "";
                int lineNo;
                Scanner input=new Scanner(System.in);
                System.out.print("Enter Line Number: ");
                int no=input.nextInt();
                try {
                    LineNumberReader ln = new LineNumberReader(new FileReader("C:/hello.txt"));
                        int count = 0;
                        while (ln.readLine() != null){
                        count++;   
                        }
                        ln.close();
                        FileReader fr = new FileReader("C:/hello.txt");

                        BufferedReader br = new BufferedReader(fr);
                        for (lineNo = 1; lineNo <= count; lineNo++) {
                            if(lineNo==no){
                                for (lineNo = no; lineNo <= count; lineNo++) {
                                       buffer.append(br.readLine());
                                       buffer.append("\n");
                                }
                            }
                            else
                                        br.readLine();
                        }
                } catch (IOException e) {
                        e.printStackTrace();
                }
                System.out.println(buffer.toString());
        }
}

Thanks









Related Tutorials/Questions & Answers:
How can i read a file from nth line onwards in java
How can i read a file from nth line onwards in java  Hi, I need to read a file content from its nth line onwards till end. How can i implement it in java. Regards, Chinnu
Read file from the Nth line
Read file from the Nth line Java provides several classes and methods to manipulate file. A file reading, is a common operation. Usually a file is to be read from top to bottom but here we are going  to read a file content from
Advertisements
How to read a line from a doc file
How to read a line from a doc file  How to read a line from a doc file   Hi Friend, To run the following code, you need to download POI... { public static void main(String[] args) { File file = null; WordExtractor
How to read big file line by line in java?
Learn how to write a program in java for reading big text file line by line In this tutorial I will explain you how you can read big file line by line... to read the big file in your java program. For example you have to process some
Read Specific Line from file Using Java
Read Specific Line from file Using Java Here we are going to read a specific line from the text file. For this we have created a for loop to read lines 1 to 10 from the text file. If the loop reached fifth line, the br.readLine() method
Java Read File Line by Line - Java Tutorial
Read Specific Line from file Using Java How to read... how to read a text file in Java one line at a time: Video Tutorial... Java Read File Line by Line - Example code of reading the text file
How to read a large text file line by line in java?
How to read a large text file line by line in java?  I have been... you kind advice and let's know how to read a large text file line by line in java... memory assigned is also a limit. So, we have decided to read the text file line
How do I read a variable from a file in shell script
How do I read a variable from a file in shell script  Hi, In my... to read some of the variables from other file and then use this in spark submit command. How do I read a variable from a file in shell script and then use
how to read file line by line using filereader in java
how to read file line by line using filereader in java  Hi, how to read file line by line using filereader in java? Thanks   Hi...))) { String line; while ((line = br.readLine()) != null
How to Read a file line by line using BufferedReader?
How to Read a file line by line using BufferedReader?  Hello Java... problem is to find the best way to read the file in Java. I just searched the google... at a time very efficiently. View the detailed example and code at Java Read File Line
How to Read file line by line in Java program
by line in Java. But there are various ways that can help read a larger file... is invocated, they can convert the bytes read from the file into characters... of read file line by line in Java is printed on console.ADS_TO_REPLACE_5
java - read file line by line in Java
java - read file line by line in Java  Hi, how one can read a text... file in Java can be read line by line with the help of BufferedReader class... the details at How to read file line by line in Java?   What is the benefits
Read from file java
Read from file java  How to Read from file java? What is the best method for a text file having a size of 10GB. Since i have to process the file one line at a time so tell me the very best method. Thank you
Java read file line by line
Java read file line by line In this section, you will learn how to read a file... are going to read a file line by line. For reading text from a file it's better... class is used to read text from a file line by line using it's readLine method
How do I read a large file quickly in Java?
How do I read a large file quickly in Java?  Hi, I my project I have... the tutorial: Java Read File Line by Line. The Scanner class can also be used... in 1-2 GB in size. What is the best way to read the file efficiently? How do I read
Java Read File Line By Line, Video Tutorial of Java Read File Line By Line
;shows you how you can write code to read a text file in Java line by line"... The java.util.Scanner class can also be used to read a file in Java line by line... a program in Java programming language to read a text file line by line. The "
Java read file line by line - Java Tutorial
; This program reads the bytes from file and display it to the user. Download...; C:\nisha>java FileRead this is a file...C:\nisha>javac ReadFile.java C:\nisha>java
How can i extract email ids from xls/xlsx file in java?
How can i extract email ids from xls/xlsx file in java?  that's the code..... i tried to extract email id;s from xls file........... but it doesn;t... org.apache.poi.poifs.filesystem.POIFSFileSystem; public class excelread123 { File
Java read lines from file
of reading file line by line in Java. Can any one share me the code for reading...Java read lines from file  Any code example related to Java read lines from file? In my project there is requirement of reading the file line by line
Java - How to read a string line per line
(System.getProperty("line.separator")); Read more at: Java Read File Line by Line Java Read File Line By Line, Video Tutorial Line by Line reading from...Java - How to read a string line per line  Java - How to read
How can i draw a line using java swings
How can i draw a line using java swings  Sir my program contains different components i am using JFrame. I want to draw a straight line between components(Jtextfeilds, Jlabels).So could you help me for it. Thank You
How can i draw a line using java swings
How can i draw a line using java swings  Sir my program contains different components i am using JFrame. I want to draw a straight line between components(Jtextfeilds, Jlabels).So could you help me for it. Thank You
How To Read Integer From Command Line In Java
How To Read Integer From Command Line In Java In this section we will discuss about how an integer can be read through the command line. In Java all... to take integer value from the command line. In this example I have created
nio read file line by line
nio read file line by line  Is there any way to read file line by line using the Java nio package? How to use the nio classes to read file line... the BufferedReader class. Check the tutorial Java Read File Line by Line - Java
How to read a file line by line?
How to Read Excel file Using Java Read Specific Line from file Using Java How to read file from Applet... of reading files in Java How To Read File In Java
How to read file in java
How to read file in java Java provides IO package to perform reading and writing operations with a file. In this section you will learn how to read a text file line by line  in java. FileInputStream- This class reads bytes from
How To Read String From Command Line In Java
How To Read String From Command Line In Java In this section we will discuss about how string can be read through the command line. In Java command line... of arguments can be read given as command line and the other will explain that how we
Java file line reader
Java file line reader In this section, you will learn how to read a particular line from file. Sometimes you want to read a particular line from the file... and parse the file path. Through the code, we want to read the line 3 of the file
how to read the .proprties file from struts - Struts
how to read the .proprties file from struts   errpr is :file..."; How to set the file path.  Hi Friend, It seems that you haven't... file in the same folder where you have put your java file. Thanks
Want to learn java - How i can learn Java from scratch?
Want to learn java - How i can learn Java from scratch?  Hi, Want to learn java - How i can learn Java from scratch? Give me some guide. Thanks   Want to learn java - How i can learn Java from scratch
How can i download these java related materials from rose india
How can i download these java related materials from rose india  How can i download these java related materials from rose india   Hello... tutorial do you want to download from the site? Please specify it. Thanks
How to read and display data from a .properties file from a jsp page
How to read and display data from a .properties file from a jsp page  I have a .properties file. I have to create a jsp page such that it reads the data from this .properties file and display it in table format. Ex:by using
Java I/O From the Command Line
Java I/O From the Command Line In this section we will learn about the I/O from the command line in Java. Several times you can see that the programs runs after taking the input from the command line. Java also supports for the command
How do I install a .deb file via the command line?
How do I install a .deb file via the command line?  How do I install a .deb file via the command line?   Hi, You can install it with following command: sudo dpkg -i DEB_PACKAGE Example: sudo dpkg -i packagename.deb
read excel file from Java - Java Beginners
read excel file from Java  How we read excel file data with the help of java?  Hi friend, For read more information on Java POI visit to : http://www.roseindia.net/java/poi/ Thanks
objective c read file line by line
objective c read file line by line  Please explain how to read files in Objective C line by line
how can i display a pdf file in a jtextarea
how can i display a pdf file in a jtextarea  I need to display a pdf file in a jtextfield or in a jtextarea.Atlest i need to displat it in a jframe.I have a button and while clicking on it ,i need to choose the pdf file and need
How can I execute a PHP script using command line?
How can I execute a PHP script using command line?  How can I execute a PHP script using command line
How can i display the distance of a line drawing randomly?
How can i display the distance of a line drawing randomly?  How can i display the distance of a line drawing randomly
Read file line by line in Java 8
Tutorial Java read file line by line - Java Tutorial How to read...? Video tutorial read file line by line How to read data from txt file... in java? How to read properties file in Java? Tutorials of Java I/O
Java read file
There are many ways to read a file in Java. DataInputStream class is used to read text File line by line. BufferedReader is also used to read a file in Java...(in)); readline() is used to read the next line. Example of Java Read File:ADS_TO_REPLACE_3
How to Read a File in Java
How to Read a File in Java? In this section we are going to know, How to read a file in Java. We have to follow three step to read a File. First get... but reading a character line by line from a file. Now we are going to read a file
How to write file by line in Java
How to write file by line in Java  How to write file by line in Java   Hi, For Write to a file by line using java programming language we... in a new line. How to use Write To File By Line in Java programs
How To Read File In Java
How To Read File In Java In this section we will discuss about about how data of a file can be read in Java. A file can contain data as bytes, characters, binary data etc. To read a file in Java we can use following of the classes
Read File from specified path in Java
How to read a file from a specified path in Java? After learning so many...: You can also read the file using the Scanner class of Java. Here is the code... Java Read File Line by Line - Java Tutorial
How to extract a specific line from a text file? - IoC
How to extract a specific line from a text file?  Hi all, i'm trying to write a code that return a specific line from a text file. so my first..., it's working fine and it's from Roseindia tutorial. But now, i want to extract the line N
Read Property file From Jmeter
Read Property file From Jmeter  Hi, I am running web driver script from Jmeter, but while reading property file I am getting "File Not Find Exception". Please tell me how to read ".properties" file from Jmeter
how can i export a .jar file include .mbd file?
how can i export a .jar file include .mbd file?  i have a project... a error that can't export .jar file width the .mdb file ? how can i import this .mdb file width the .jar file? and how can i run this file on the other computer
how can i draw line between two panel contaning circle and line between their center?
how can i draw line between two panel contaning circle and line between their center?   how can i draw line between two panel contaning circle and line between their center
How to read data from txt file and save to database MySql - Java Beginners
How to read data from txt file and save to database MySql  Please help me again ,my problem right know is how to read data from txt file then data...(in)); String strLine; //Read File Line By Line while ((strLine

Ads