Two Laptop Bag*
The moose likes Beginning Java and the fly likes Read and search for text in a file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Read and search for text in a file" Watch "Read and search for text in a file" New topic

Read and search for text in a file

Hari MohanSingh

Joined: Dec 19, 2010
Posts: 4
I have a file like this
ABCD 123 blah blah
int varx;
string varb;

xyz = varb;

blah blah

What I need to do:
search in the file for xyz and find varb and then find
string varb;
and extract what it is a string.

so the definition of varb is before it is used, so I need to find if it is used and then find what it is defined as.

How do I do this? The file will be Unix formatted but stored locally on a DOS machine.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 37941
Do you know how to find a String inside a String?
I agree. Here's the link:
subject: Read and search for text in a file
Similar Threads
NumberFormatException problem
backslash n is being escaped against my will
getRequestDispatcher(), relative path problem...
Adding html tags to script
Help with Java