Solved

String with String not match

Posted on 2004-04-17
6
288 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
Comment Utility
>>it not working.

What do you mean by that?
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
Don't forget to initialize Keyword next to AllLine

String AllLine = null;
String Keyword = null;

0
 

Author Comment

by:sarauwa
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 92

Accepted Solution

by:
objects earned 100 total points
Comment Utility
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
Comment Utility
and of course close it at the end of the inner loop :)
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
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.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now