?
Solved

how to find the specific line of a file

Posted on 2011-03-17
5
Medium Priority
?
215 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 2000 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month12 days, 6 hours left to enroll

752 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