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?
Delete specific lines from text in Java
Advertisements
ModuleNotFoundError: No module named 'extract-specific-sites-from-msa'
ModuleNotFoundError: No module named 'extract-specific-sites-from-msa'
java write to a specific line
how to read 100 text files from a folder or directory and write the data into a single file.using java programming?
How to read a large text file line by line in java?
how to search a text in all files in a folder in unix
how to search a text in all files in a folder in unix
how to search a text in all files in a folder in unix
how to search a text in all files in a folder in unix
Read specific column data from text file in java
How to remove specific element from Hashset.
How to Convert Text Files into Gzip File
How to write file text In New Line
How to extract name,surname, doamin name from mailid
ModuleNotFoundError: No module named 'extract-specific-lines'
ModuleNotFoundError: No module named 'extract-specific-lines'
How to run PHP Script from the command line ?
How to extract values from SOAP Response message and insert in database
How to copy text from a gif image
How to invoke method of a library from command line
extract data from HTML
how to copy files from remote location to local using java?
Text Files
how to match the key word from a text file
How to Generate XML files from the data in DB tables?
How can i read a file from nth line onwards in java
How to run java swing application from jar files .
How to Read a file line by line using BufferedReader?
How to Check Markup in PHP File from Command Line

Ads