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

 
 


Chinnu
How can i read a file from nth line onwards in java
1 Answer(s)      2 years and 4 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

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 Pages:
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
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
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 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
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 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
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 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
Tutorial you will learn how to write java program to read file line by line. We will use the DataInputStream class to Read text File Line by Line. Class... Java Read File Line by Line - Java Tutorial
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 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
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 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 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
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 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 text File
Read text File  Hi,How can I get line and keep in a String 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
read from cmd syntax and open the file
read from cmd syntax and open the file  i have to read the name of the database e.g., "database.txt" file from a cmd syntax and open it: java FindKeys database=db.txt;minjoinrows=integer|all how can i do
read from cmd syntax and open the file
read from cmd syntax and open the file  i have to read the name of the database e.g., "database.txt" file from a cmd syntax and open it: java FindKeys database=db.txt;minjoinrows=integer|all how can i do
Java Read CSV file
Java Read CSV file In this tutorial, you will learn how to read csv file. CSV (Comma Separated Value) is a common type of data file which can be exported... the data from this file in a line at a time. Then we have used StringTokenizer class
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
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
Read Lines from text file
Read Lines from text file  Here's a brief desc of what my Java code does .. I'm using BufferedReader to read lines from a text files and split each... read from the text file and displays the output as desired. Unable to read the rest
how to write and read text for javaME
from the library? i want to type multiple line on text file then, read it from java me coding.. can u helps me? it is urgent. i have to submit this project...how to write and read text for javaME  Hi. I have tried ur read
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
Java Write To File By Line
Java Write To File By Line In this tutorial you will learn how to write to file by line Write to a file by line using java you can use the newLine() method... how to write to file by line. In this example I have first created a new text
Java - Read file Applet
of the reading file from an applet. This program illustrates you how an applet can read the content from the given file. In this program we passes the file name... Java - Read file Applet      
Java file read write operation
Java file read write operation  how to read and write the data from text file.Suppose i have text file with 4 fields name ,roll no ,marks1,marks2..."+sal1); for complete tutorial you can follow this link Java ObjectOutputStream
Read the value from XML in java
the permissions on that file.So how can i read that value. This is little urgent...Read the value from XML in java  Hi, i have an XML with the following code. I need to get the path("D
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 PARSE FILE WITH SEVERAL DELIMITERS AND LINE FEEDERS - Java Beginners
HOW TO PARSE FILE WITH SEVERAL DELIMITERS AND LINE FEEDERS  Hi All i need to parse a file of this format,such that i can get/fetch the values... class Read{ public static void main(String[]args) throws Exception
How to check if a file is read-only in java
How to check if a file is read-only in java A read-only file is any file... will not be able to make changes to it. You can make a file read-only by using... file: Java API provides the functions to find if any file is read only
Java file line count
Java file line count In the section, you will learn how to count the number of lines from the given file. Description of code: Java has provide various... class here, to read  all the lines from the file. You can see in the given
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
Read File in Java
Read File in Java This tutorial shows you how to read file in Java. Example... shows you how to read file in Java * */ public class ReadFileExample { public... ReadFileExample Reading File from Java code Data is: Line 1
file read
file read  hi i am reaing from a file which has punjabi words. can some one help with me some code
Read Write
Read Write  Hi; How can I read certain line of say 10 text files and write to one text file   Java Read Multiple Files and store the data... OnlyExt("txt"); File f=new File("C:/"); File[] files = f.listFiles(ff); for(int i=0
how to write to file at the end of the line
how to write to file at the end of the line  Hi, Where do i learn how to write to file at the end of the line using Java program. Plz suggest... will help you for "How to write the file at the end of line using Java language
Read page from Web server
disk in a file. So, with the hop of java program you can download the HTML pages... Java NotesRead page from Web server The Java io package provides... is the complete example code in Java which reads the data from website and prints
Java read properties file
Java read properties file In this section, you will learn how to read... the above code, you can read any properties file. Output... files. Now to load the data from the properties file, we have used Properties
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
java read file
java read file  Hello i need some help... i want to read an MS Excel file in java so how to read that file
Java read latest file
Java read latest file Java provides IO package to perform file operations. Here we are going to read the last modified file. For this, we have used..., read that particular file. Here is the code: import java.io.*; import
File I/O - Text Files
Java NotesFile I/O - Text Files Java can read several types of information from files: binary, Java objects, text, zipped files, etc. One of the most.... File inFile = new File(in.next()); // File to read from. File

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.