Solved

String with String not match

Posted on 2004-04-17
6
305 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

630 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