Results 1 to 6 of 6
  1. #1
    vasavi.singh is offline Member
    Join Date
    Feb 2009
    Posts
    24
    Rep Power
    0

    Default Writing the data into RandomAccessFile

    I have a doubt in writing the data into a file which is of type RandomAccessFile.

    My prob is, Initially I am reading input of type String and int from keyboard and this part is done by the program called AddingNewArticleInfo.java.

    In Main.java I am reading the data whatever I entered and storing them in different variables.
    I would like to store this data. For that I have used FileOutputStream and PrintStream. I was able to see the data whatever I entered, in the file of type FileOutputStream. I would like maintain the data which is entered in previous runs. The problem here I am getting is whenever I rerun the program the new entered data is overwritting the old data. But I would like to maintain the data in previous runs as well as upcoming runs also.

    How can I maintain whole data in a single file.Can u tell me that way how to maintain the data.

    eg:
    In 1st run: The data is

    VASAVI 23

    In 2nd run I entered the data

    Java Forums 2000

    Iam using Output.txt to store this data.
    For 1st run it is showing: VASAVI 23
    In 2nd run it is showing: Java Forums 2000

    But I would like a maintain file which stores
    VASAVI 23 as well as Java Forums 2000.

    Please try to send an example which explains this concept.

    Thanking You,

    With Sincere regards,
    Vasavi

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    If it's a RandomAccessFile, use seek to go to the end of the file before you start writing.

    But, it would be much easier to simply use a FileOutputStream in Append mode. Look at the varying constructor definitions in the API docs for FileOutputStream.

  3. #3
    Join Date
    Jan 2009
    Posts
    56
    Rep Power
    0

    Default

    ok i ll try it.
    Thank you

  4. #4
    vasavi.singh is offline Member
    Join Date
    Feb 2009
    Posts
    24
    Rep Power
    0

    Default

    Quote Originally Posted by masijade View Post
    If it's a RandomAccessFile, use seek to go to the end of the file before you start writing.

    But, it would be much easier to simply use a FileOutputStream in Append mode. Look at the varying constructor definitions in the API docs for FileOutputStream.
    Thank u. In text book it is given few constructor in which that appending arg constructor is not available. Later browsing the net I got the same point wht u told.

  5. #5
    ii88xix88ii is offline Member
    Join Date
    Jan 2013
    Location
    Philippines
    Posts
    14
    Rep Power
    0

    Default Re: Writing the data into RandomAccessFile

    ~is there a method in RandomAccessFile that you can have an output like:

    Name: <name>
    Address: <address>
    Contact: <contact>

    Name: <name>
    Address: <address>
    Contact: <contact>

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,433
    Blog Entries
    7
    Rep Power
    20

    Default Re: Writing the data into RandomAccessFile

    Don't awaken ancient threads that have been long dead; start your own thread, it's free ... I'm locking this thread.

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Reading data from Micrsoft excel and writing to notepad
    By abhishek.jain in forum New To Java
    Replies: 4
    Last Post: 01-29-2009, 08:12 AM
  2. Writing Data or Objects?
    By Goodwine in forum New To Java
    Replies: 2
    Last Post: 11-26-2008, 12:36 AM
  3. error while retrieving data from data base
    By kirtesh4u in forum New To Java
    Replies: 5
    Last Post: 11-15-2008, 04:10 PM
  4. Replies: 0
    Last Post: 10-31-2008, 02:13 PM
  5. Data Sorting in a .data file using java
    By stutiger99 in forum New To Java
    Replies: 2
    Last Post: 10-08-2008, 02:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •