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
Login         

View Questions and Answers by Category

Advertisements


 
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 10 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
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
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
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
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
 

 

 

DMCA.com