Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners How can i read a file from nth line onwards in java

Have Programming Question? Ask it here!
 
 
 


Chinnu
How can i read a file from nth line onwards in java
1 Answer(s)      3 years and 7 months ago
Posted in : Java Beginners


Hi,

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

Regards, Chinnu


Advertisement
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 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
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... void main(String[] args) { File file = null; WordExtractor extractor = null
Java Read File Line by Line - Java Tutorial
Read Specific Line from file Using Java... tutorial that explains you how to read a text file in Java one line at a time... 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
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
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...() method is invocated, they can convert the bytes read from the file...()?. The output of read file line by line in Java is printed on console
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
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
Java Read File Line By Line, Video Tutorial of Java Read File Line By Line
a program in Java programming language to read a text file line by line. The "Java Read File Line by line" is most searched topics by the Java developers... code to read a text file in Java line by line. Steps to create a test
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
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
How to read a file line by line?
Using Java Read Specific Line from file Using Java... to read the file in Java. Here are few tutorials which you can find helpful... How To Read File In Java with BufferedReader Read
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... value from the command line. In this example I have created a class named
Java read file line by line - Java Tutorial
; This program reads the bytes from file and display it to the user. Download...:\nisha>java FileRead this is a file C...C:\nisha>javac ReadFile.java C:\nisha>java
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 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 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... while loop to read any number of input from the command line. In while loop I
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
How to read file in java
How to read file in java Java provides IO package to perform reading... file line by line  in java. FileInputStream- This class reads bytes from...-independent way.  BufferedReader-This class read the text from a file line
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 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 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
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 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
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... but reading a character line by line from a file. Now we are going to read a file... can be very inefficient. Example Here is the program to read a file in Java
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
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 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 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
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
How To Read File In Java with BufferedReader
How To Read File In Java with BufferedReader class - example code This tutorial shows you how you can read file using BufferedReader class in your program... java.io.*; /** * How To Read File In Java with BufferedReader class
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
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... line. Example of Java Read File: package FileHandling; import
How to read the .doc/ .docx file in Java Program
How to read the .doc/ .docx file in Java Program  Hi, I am beginner in Java programming language. Can anybody explain How to read .doc file in Java.... This way you can read the .doc or .docx file in Java programming language. Thanks
How can I learn Java?
How can I learn Java?  Hi, I have just completed a course in HTML.... Now I want to learn Learn Java programming and become the expert in Java programming. How can I learn Java? in shortest possible time. I mean I just want to begin
How to Check Markup in PHP File from Command Line
How to Check Markup in PHP File from Command Line  Check Markup in PHP File from Command Line   PHP has a feature that allowed you to check... try this: http://www.phpzag.com/check-markup-in-php-file-from-command-line
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
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
how to read and write an xml file using java
how to read and write an xml file using java  Hi Can anyone help me how to read and write an xml file which has CData using java
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 open my Java desktop app by clicking on its file?
How can I open my Java desktop app by clicking on its file?  How can I open my Java desktop app by clicking on the file it creates? This app creates... file open by a double click from windows explorer, and to open inside BlueSky app
how read data from doc file in same formate in jsp
how read data from doc file in same formate in jsp  how we can read and display data on jsp page, from doc file with the same formatting
How to read properties file in java
How to read properties file in java Description of Example:- In this example...= 8285279608 Example of Read properties file in java import java.io.... to a stream or load from a stream using the properties file. This properties
how to read values from java in xml?
how to read values from java in xml?  how to read values from java in xml
How I can filling pdf file that crated by livecycle using itext
How I can filling pdf file that crated by livecycle using itext  I have pdf file that already done by livecycle.. I read it then I used... else than origional pdf file . My request ... I want to use pdfreader to read
C file read example
C file read example       This section demonstrates you to read a line from the file. You can see in the given example, we prompt the user to enter the name of the file to read
Advertisements
 

 

 

DMCA.com