Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

SEARCHING AND SAVING FILES

  Asked By: John    Date: Dec 28    Category: Java    Views: 709
  

I am required to search for a client, using their surname, first name
or age and display a list of all their matching records in the text
area if the results are found.

Then i am required to save the data and load it from a file using an
application and not an applet. If this information is validated then
the user should be able to select the client and account from a
choice list. This means that each time a client object is created an
entry is added to the list of clients showing the client ID, surname
and first name. When a client number is entered in the text field (or
selected from the list) all accounts that are owned by the client
will be displayed in a choice list. Each choice list entry for an
account must show the account number and the account type.

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Bama Cohen     Answered On: Dec 28

I just wanted to make sure i did this correct, but
i dont think i have. Could you please let me know what
i have dont wrong.


Here is my code:
*******************************************************
public static void clntWrite(Vector clntData) throws
FileNotFoundException, IOException
{
DataOutputStream dos = new DataOutputStream(new
BufferedOutputStream(new
FileOutputStream("clnt.dat")));

try
{
for (int i = 0; i< clntData.size(); ++i)
{
Client aClient = (Client)clntData.elementAt(i);
dos.writeInt(aClient.getAccNo());
dos.writeUTF(aClient.getSurname());
dos.writeUTF(aClient.getFirstName());
dos.writeUTF(aClient.getAge());
//dos.writeInt(aClient.getAccDetails());
}//end for loop
dos.flush();
dos.close();
System.out.println("Client information  saved...");
}//end try
catch (Exception e)
{
System.out.println("Unable to save  account information
to client.dat" );
System.out.println("Error: " + e.getMessage());
}
}//end clntWrite method

public static Vector clntRead(Vector clntData) throws
FileNotFoundException, IOException
{
DataInputStream dis = new DataInputStream(new
BufferedInputStream(new FileInputStream("clnt.dat")));

while (dis.available()>0)
{
Client aClient = new Client();
aClient.setAccNo(dis.readInt());
aCustomer.setSurname(dis.readUTF());
aCustomer.setFirstName(dis.readUTF());
aCustomer.setAge(dis.readUTF());
//aCustomer.setAccDetails(dis.readInt());
clntData.addElement(aClient);

}//end while
dis.close();
return clntData;

}//end clntRead method

 
Didn't find what you were looking for? Find more on SEARCHING AND SAVING FILES Or get search suggestion and latest updates.




Tagged: