RandomAccessFile: Add a record will overwrite the existing records.

Posted on 2006-05-21
Last Modified: 2010-05-18
I need help from experts! I added a record to a text file by using RandomAccessFile. The record  added (and overwrite) the first record.  Any suggestion?

RandomAccessFile rf = new RandomAccessFile("List.txt", "rw");
String newRecord = "add me in the last record";

Question by:Wonder19
    LVL 86

    Accepted Solution

    You need to seek to the end of the file first

    RandomAccessFile rf = new RandomAccessFile("List.txt", "rw");;

    Author Comment

    it works well.  Thanks for your quick response! THANK YOU!

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Connect to IP Camera using Java 4 64
    wordsCount challenge 10 49
    java continue statement 10 53
    countAbc challenge 9 35
    Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
    Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now