How to extract a specific line from a text file?

Ads
 

How to extract a specific line from a text file?

View Answers

July 30, 2009 at 12:39 PM

Hi Friend,

Try the following code:

import java.io.*;

public class ReadSpecificLine{

public static void main(String[] args){
String line = "";
int lineNo;
try {
FileReader fr = new FileReader("C:\\Employee.txt");
BufferedReader br = new BufferedReader(fr);
for(lineNo=1;lineNo<10;lineNo++){
if(lineNo==5){
line = br.readLine();
}
else br.readLine();
}
}
catch (IOException e){
e.printStackTrace();
}
System.out.println("Line: " + line);
}
}

Hope that it will be helpful for you.
Thanks

July 31, 2009 at 2:11 AM

Thank you very much friend.
i will continue my experience with this example.

i will comeback to you later.
Best Regards

August 4, 2009 at 2:47 AM

Now i try to extract one more line from my text file, here is my code but it's not working, why please?

#
import java.io.*;

public class ReadSpecificLine
{

public static void main(String[] args)
{
String line = "";
int lineNo;
try
{
FileReader fr = new FileReader("C:\\IMS.txt");
BufferedReader br = new BufferedReader(fr);
for(lineNo=1;lineNo<10700;lineNo++)
{
if(lineNo==5134)
line = br.readLine();
else
if(lineNo==5100)
line = br.readLine();
{
catch (IOException e)
{
e.printStackTrace();
}
System.out.println("Line: " + line);
}
}
#

August 19, 2009 at 3:13 PM

Hi friend,

thank you very much for the solution.
SPX

Ads









Related Tutorials/Questions & Answers:
How to extract the entire line with specific data from a Text in java?
How to extract a specific line from a text file? - IoC
Advertisements
Read Specific Line from file Using Java
Java to extract info from .iCalendar files
java write to a specific line
Delete specific lines from text in Java
How to read a large text file line by line in java?
How to extract details from XML? - JSP-Servlet
how to read 100 text files from a folder or directory and write the data into a single file.using java programming?
Read specific column data from text file in java
How to extract name,surname, doamin name from mailid
How to write file text In New Line
How to print differences of two text files
How to Convert Text Files into Gzip File
How to remove specific element from Hashset.
extract data from HTML
How to extract values from SOAP Response message and insert in database
How to run PHP Script from the command line ?
How can I Convert my Image Files to Text Files? - IDE Questions
How to read a line from a doc file
How to invoke method of a library from command line
Extract frames from Video File
How can we extract string 'roseindia.net ' from a string http://[email protected] net using regular expression of php?
extract content from javamail - JavaMail
Text Files
How to Read a file line by line using BufferedReader?
How can i read a file from nth line onwards in java
How to copy text from a gif image
Write Text To File In New Line.
How to read text from - Java Beginners
How to Check Markup in PHP File from Command Line

Ads