• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can't found id inside test.txt always not found result  RSS feed

 
mich onicha
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37469
539
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please ellaborate about the problem. What do you type? What is the error? What do you know about the problem so far?
 
mich onicha
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my code problem , the code must search the id number inside the notepad if its true must say found ,but its is false its must say not found........ and here the code problem its always says not found please help me.
 
mich onicha
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


System.out.println("******** a to add || s to search ********");
System.out.println("Enter Choice: "); //user enters his/her choice
ans = input.next();

if (ans.equals("a")) { //if the user choice == "y"

System.out.print("Enter ID: "); //enter id
ID = input.next();

System.out.print("Enter Firstname: "); //enter 1st name
firstname = input.next();

System.out.print("Enter Lastname: "); //enter last name
lastname = input.next();


output.println(ID + "," + firstname + "," + lastname + ""); //print the information to the textfile
output.close(); //close the file
System.out.println("Your file has been written"); //notify the user that the information he/she inputs are already saved in the text file
} else if (ans.equals("s")) //if the user inputs "s" the program will try searching for the id information
{

BufferedReader getIt = new BufferedReader(new InputStreamReader(System. in ));
String userIN = "";

try {

FileInputStream fstream = new FileInputStream("test.txt");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader( in ));
String strLine;
System.out.println("Enter ID: ");
userIN = getIt.readLine();

while ((strLine = br.readLine()) != null) {

if (userIN.equals(strLine)) { //
System.out.println("");
} else {
System.out.println("File not found");
}
}

in .close();
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}

}
}
}
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!