Solved

how to find the specific line of a file

Posted on 2011-03-17
5
214 Views
Last Modified: 2012-06-21
Hi,
In Java, I know the path to the file.

Now, I want to find the specific line of this file and assign it to a variable.

The line that I wanna find looks like this:

# SOMEDATEandTIME (SOMETEXT)     SOMEDIGITNUMBER    <a href='http://SOMEPATH/SOMETEXT.html'>SOMETEXT</a>

SOMEDATEandTIME are in this format:  2011/03/04-15:10:20

How can I make it?

Thanks,

0
Comment
Question by:Tolgar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
5 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 35160380
You can read file line by lin and then
find the line where

s.indexOf( "<a href='http://SOMEPATH/SOMETEXT.html'>SOMETEXT</a>") > -1)


0
 
LVL 47

Expert Comment

by:for_yan
ID: 35160389


DataInputStream in = new DataInputStream(new FileInputStream("file_path_nmae"));
String buff = null;
while((buff= in.readline()) != null){
if(buff.indexOf( "<a href='http://SOMEPATH/SOMETEXT.html'>SOMETEXT</a>") > -1)
System.out.println(buff);

}
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35160400

String s;

try
{
DataInputStream in = new DataInputStream(new FileInputStream("file_path_nmae"));
String buff = null;
while((buff= in.readline()) != null){
if(buff.indexOf( "<a href='http://SOMEPATH/SOMETEXT.html'>SOMETEXT</a>") > -1)
System.out.println(buff);
s=buff;

}

in.close();

}catch(Exception ex){
ex.printStackTrace();
}

System.out.println("s: " + s);

This would actully print the last line which matches this pattern

 
0
 
LVL 47

Accepted Solution

by:
for_yan earned 500 total points
ID: 35160414
corrected (forgot braces in the above):

String s;

try
{
DataInputStream in = new DataInputStream(new FileInputStream("file_path_nmae"));
String buff = null;
while((buff= in.readline()) != null){
if(buff.indexOf( "<a href='http://SOMEPATH/SOMETEXT.html'>SOMETEXT</a>") > -1){
System.out.println(buff);
s=buff;
}

}

in.close();

}catch(Exception ex){
ex.printStackTrace();
}

System.out.println("s: " + s);

This would actully print the last line which matches this pattern
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35160433
If you can have some other lines which have the same
ending but different format of date - then you'll want to add
another clause i the "if" check in order to differentiate between the
two time formats.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question