*
The moose likes I/O and Streams and the fly likes Java File Reading 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 "Java File Reading" Watch "Java File Reading" New topic
Author

Java File Reading

Nanditha Buddhavarapu
Greenhorn

Joined: May 28, 2002
Posts: 2
Hi..
I have a file AddressBook.dat that has as contents:
ID Name Address City State Zip
1. John Small 123 Main St. Laurel MD 20708
2. Fig F. Big 1145 Techie Dr. New York NY 45446
I have to create a Java program that takes ID as input and prints out the name,address etc for that ID separately.
Can sumone help me how to use BufferedReader as I am new to Java???
Joe Joe
Greenhorn

Joined: Sep 13, 2002
Posts: 5
Well I am not sure what you are wanting to do
but this shows how to use the bufferedReader
if ya need anymore help just ask
kavins
Greenhorn

Joined: Sep 14, 2002
Posts: 15
i'll be more precise!!
Implement an Object called AddressReader that will be able to open and read the file entitled AddressBook.dat.
AddressBook.dat
1.John Smith 123 Main St. Laurel MD 20708
2.Greg F. Jones 1145 Technology Rd. New York NY 45456
3.Tim Roberts 1324 Basswood Dr. Arlington VA 20166
.
.
.
.
File Format Rules

Position number followed by a .
Full name either first name and last name or first name, middle initial with a . and last name
Address- Street number, Street name, and either Dr, St, or Rd which always ends with a .
City - 1 or more words
State - 2 letter abbreviation
Zip - 5 number code
Class AddressReader will need to have the following functions
int getTotalEntries( );
String getName(int position) - returns the name as a String according to the position provided in the parameter.
String getAddress(int position)
String getCity(int position)
String getState(int position)
String getZip(int position)
There will be a Class Client that has its own main and will instantiate an AddressReader and call its methods.
class Client {
public static void main(String[] args) {
AddressReader add = new AddressReader();
for (int i=0;i<add.getTotalEntries(); i++){
String name = add.getName(i);
String address = add.getAddress(i);
String city = add.getCity(i);
String state = add.getState(i);
String zip = add.getZip(i);

int entry = i+1;
//prints out the contents of AddressBook.dat
System.out.println("Address Entry: "+ entry);
System.out.println("_______________");
System.out.println("Name: "+ name);
System.out.println("Address: "+address);
System.out.println("City: "+city);
System.out.println("State: "+state);
System.out.println("Zip: "+zip);
}
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

This looks a lot like a homework assignment
Just a warning that we offer help but not solutions for homework
and...
"kavs",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp.
We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please edit your profile and select a new name which meets the requirements.
Thanks.
Dave
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java File Reading
 
Similar Threads
File IO with Servlet
update while doing save in hibernate
xml to java objects
Basic hibernate code explanation
Weird update vs insert vs select from DB