Solved

String with String not match

Posted on 2004-04-17
6
300 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
  • 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
Technology Partners: 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

756 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