Solved

String with String not match

Posted on 2004-04-17
6
301 Views
Last Modified: 2010-03-31
Hi,

I try to find text from text file that refer to another text file.
Why when I use hard code it working but if I read text file and compare with another text file it not working.
My program is as follows:

String AllLine = null;
String ThirdPartyList;
String FindTP;
ThirdPartyList = ("D:/ThirdPartyTest.txt");
FileReader FRTP = new FileReader(ThirdPartyList);
BufferedReader BRTP = new BufferedReader(FRTP);
inFileName = ("D:/SourceMain.txt");
FileReader fileReader1 = new FileReader(inFileName);
BufferedReader br1 = new BufferedReader(fileReader1);
int check1 = 0;

while ((Keyword = BRTP.readLine()) != null)
{
  Keyword = Keyword.substring(Keyword.indexOf("123"),  
                                              Keyword.length());
  Keyword = Keyword.toLowerCase();
  while ((AllLine = br1.readLine()) != null)
  {
    AllLine = AllLine.toLowerCase();
    int index = AllLine.indexOf(Keyword);//here is a problem
    if (index != -1)//text found
    {
       check1 = 1;
       break; //exit while loop when found
                              }
  }//end while
  if (check1 == 1) break;
}//end while
BRTP.close();
br1.close();


if (check1 == 0) {
  JOptionPane.showMessageDialog(StartFrame, "Text Not Found");
}else{
  JOptionPane.showMessageDialog(StartFrame, "Text Found");
}//end else if

Thank you
sara
0
Comment
Question by:sarauwa
[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
  • 3
  • 2
6 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 10849209
>>it not working.

What do you mean by that?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10849219
Don't forget to initialize Keyword next to AllLine

String AllLine = null;
String Keyword = null;

0
 

Author Comment

by:sarauwa
ID: 10851109
It's not working because message "Text Not Found" appear even the text exist in both text file.
I have put value null for both Keyword and AllLine.

Example data:
1. Data in text file ThirdPartyTest.txt
abc123aaaaa
defghi123bbbbbbbbbbb
jk123cccc
mnopqr123dddddddddd

2. Data in text file In SourceMain.txt
abc def ghi
jklmno123cccc(this data suppose be found cos same with line 3)
abd xyz

For example if I set hard code Keyword="123cccc" text found but it not work when I read from text file ThirdPartyTest.txt then search in SourceMain.txt

Thank you
sara

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 92

Accepted Solution

by:
objects earned 100 total points
ID: 10851150
you only read the second file once for the first  keyword.
you need reopen the second file for every keyword.

while ((Keyword = BRTP.readLine()) != null)
{
  Keyword = Keyword.substring(Keyword.indexOf("123"),  
                                              Keyword.length());
  Keyword = Keyword.toLowerCase();
  FileReader fileReader1 = new FileReader(inFileName);
  BufferedReader br1 = new BufferedReader(fileReader1);
  while ((AllLine = br1.readLine()) != null)
0
 
LVL 92

Expert Comment

by:objects
ID: 10851151
and of course close it at the end of the inner loop :)
0
 
LVL 92

Expert Comment

by:objects
ID: 10856548
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
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.
Suggested Courses

710 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