File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes I/O and Streams and the fly likes Get Datas in My text file -Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Get Datas in My text file -Java" Watch "Get Datas in My text file -Java" New topic

Get Datas in My text file -Java

Chaos Knight

Joined: Mar 05, 2013
Posts: 1
Hi can someone help me !

I am stack with this problem.. All I want is that I want to view Employees Data. The Data was save in my Notepad and this is what is in my Notepad.


I can show all the data's in my Employee.txt by having this code: ...

this is the output of the program:

But I want that when I run the program It will ask to enter a FullName then If a FullName is entered It will search in my Employee.txt and if found it will display the Data's of the Employee.

I want to have this output:

I am hoping and waiting for an answer.
Thank You..
T Mishra
Ranch Hand

Joined: Apr 04, 2006
Posts: 108

Hi Chaos,

Welcome to the Ranch

Here's one of the approaches you can think of. You may also divide it into multiple methods, with each method doing a specific task.
1. Get employee name as user input.
2. Assuming, the data in the file is consistent across all the lines, find the user entered name in any line. Lets call it as findEmployee().
3. check if there exists a line in which the user entered name was found - lets call it as exists()
4. if the employee name is found, print it into the console as you are doing for all the employees in a do while loop. lets call this method as printEmployee()
5. if not found, print a message.

Tushar (SCJP 1.5)
Tony Docherty

Joined: Aug 07, 2007
Posts: 2839
An alternative approach (if the whole file can be loaded and stored in memory and you are planning on looking up multiple names) would be to read in the file, store the details of each employee in instances of an Employee class and then store the instances in a Map keyed on the user name.
James X Peterson
Whizlabs Java Support
Ranch Hand

Joined: Feb 26, 2013
Posts: 158
Hi Chaos Knight,

following code is the code for the output you required

[MODERATOR EDIT] Removed full code solution.

James Peterson, please remember this site is NotACodeMill(←click). Thanks!
I agree. Here's the link:
subject: Get Datas in My text file -Java
It's not a secret anymore!