Comparing strings from a file

Here is a question to roll around in your heads.

if I have 2 files that are identical except a few variables might be different, how do I compare them to see that they match?

the variables look like this:


and there are 2 files that have these types of variables.

How do I read the variable by parameter in one page and find the same parameter in the second file and then compare the values?

Does that make sense?

I appreciate the time.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi k41d3n,

I would use Properties class to read/write the two files.  Properties are stored in (key,value) pairs and it's easy to compare two Properties objects with a loop, something like:

import java.util.Properties;

Properties prop1 = new Properties(), prop2 = new Properties();
FileInputStream in = new FileInputStream(new File("file1"));
in = new FileInputStream(new File("file2"));
for (Enumeration e = prop1.propertyNames() ; e.hasMoreElements() ;)
  String key = (String) e.nextElement();
  String value1 = prop1.getProperty(key);
  String value2 = prop2.getProperty(key);
  if(value2 == null)
    System.out.println(key + " is not present in file two");
  else if(value2.compareIgnoreCase(value1) != 0)
    System.out.println(key + " in file 1 has different value than in file two");


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
k41d3nAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.