How to extract a specific line from a text file?

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









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
ModuleNotFoundError: No module named 'extract-specific-sites-from-msa'
ModuleNotFoundError: No module named 'extract-specific-sites-from-msa'
Java to extract info from .iCalendar files
Delete specific lines from text in Java
java write to a specific line
Read specific column data from text file in java
ModuleNotFoundError: No module named 'extract-specific-lines'
ModuleNotFoundError: No module named 'extract-specific-lines'
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 extract details from XML? - JSP-Servlet
How to remove specific element from Hashset.
How to extract name,surname, doamin name from mailid
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
How to print differences of two text files
How to write file text In New Line
extract data from HTML
How to Convert Text Files into Gzip File
How can I get specific data from JSON
ModuleNotFoundError: No module named 'filee'
ModuleNotFoundError: No module named 'filem'
ModuleNotFoundError: No module named 'filez'
Text Files
ModuleNotFoundError: No module named 'filex'
ModuleNotFoundError: No module named 'filex'
How to extract values from SOAP Response message and insert in database
How can I get specific data from JSON
extract content from javamail - JavaMail
How to extract HTML elements from a page?
How to extract HTML elements from a page?
Extract frames from Video File
How to run PHP Script from the command line ?
How to read a line from a doc file
How to invoke method of a library from command line
autocomplete(): Spring mvc with jquery: I am not getting correct value in the text filed. Please help me
How can I Convert my Image Files to Text Files? - IDE Questions
While retrieving text from database onto JSP, the alignment of line and paragraphs is not followed
How to copy text from a gif image
How to get specific index value from int buffer.
How can we extract string 'roseindia.net ' from a string http://deepak@roseindia. net using regular expression of php?
How to get specific index value from long buffer.
How to get specific index value from short buffer.
How to read text from - Java Beginners
ModuleNotFoundError: No module named 'extract-from-url'

Ads