Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Java File Handling

  Asked By: Alex    Date: Aug 30    Category: Java    Views: 948
  

I 'm doing a simple program on file handling in JAVA.
I need to store 3 data

1 First Name
2 Last Name
3 Phone Number
in to a file. (Not a Database). I
tryed to do it using
datainputstreams etc.. But when i enter the second record it
over writes the first record.
How can i over ome this problem

Also I hav to display all the records in a table after entering.
It has to be worked even I close the program and reopen it.

It would be greatful if any one can help me on my program.

Share: 

 

3 Answers Found

 
Answer #1    Answered By: Garrett Brooks     Answered On: Aug 30

It seems like you are closing the output stream after writing each line. The
trick here is to keep the file  (output stream) open and close  it after write is
complete or in the finalize block.

For more details follow this:
java.sun.com/.../overview.html

 
Answer #2    Answered By: Willis Hill     Answered On: Aug 30

wat u are asking for can easily done...using files...if u could go through the
documentation ...i wl give u a hint...try using random access files

The following code creates a RandomAccessFile to read the file  named
farrago.txt:
new RandomAccessFile("farrago.txt", "r");
And this one opens the same file for both reading and writing:
new RandomAccessFile("farrago.txt", "rw");

 
Answer #3    Answered By: James Williams     Answered On: Aug 30

I like to learn java  and I am
learning.. Actually this is for one of my assignmnets.. the
thing is I have to submitthe assignmnet on friday. So I don't
hav much time to work on it. If you can help  me with my other
questions also that will be great help.

 
Didn't find what you were looking for? Find more on Java File Handling Or get search suggestion and latest updates.




Tagged: