instead of if(s1==s2) try if(s1.trim().equals(s2.trim())) On Jun 15, 11:14 am, ρ Я д Ŧ έ e Қ ....Me |\|0T ThaT BaDD*** <[email protected]> wrote: > PLS HELP!!!hey please help me with this...... > i have written a program to search a string entered through key board in a > file..... > and if found display all the contents of the file....the program is as > under: > import java.util.*; > import java.io.*; > public class search > { > public static void main(String args[]) > { > String str; > try > { > BufferedReader b1= new BufferedReader(new FileReader("34.txt")); > BufferedReader b2= new BufferedReader(new InputStreamReader(System.in)); > int i=0; > System.out.println("Enter the name to be searched:"); > String s1=b2.readLine(); > String s2,s3; > while((s2=b1.readLine())!=null) > { > if(s1==s2) > {BufferedReader b3= new BufferedReader(new FileReader("34.txt")); > i=1; > while((s3=b3.readLine())!=null) > {System.out.println(s3);} > b3.close();} > } > > if(i!=1) > System.out.println("The name not found"); > b1.close(); > b2.close();} > > catch (FileNotFoundException fnfe) > { > System.out.println(fnfe); > return;} > > catch (IOException ioe) > { > System.out.println(ioe);} > } > } > > but the problem is it shows no error but prints the mess "the name not > found" > when i enter the name as Prateek and the content of file is as under > //contents of file 34.txt > Prateek > hostel no 4 > manit > why is this happening.....please xplain..... > hoping a quick reply..... > thanx in advance > bbye
--~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/javaprogrammingwithpassion?hl=en -~----------~----~----~----~------~----~------~--~---
