Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7980941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:13:25+00:00 2026-06-04T10:13:25+00:00

If I create a java Random Access File object against a file. What happens

  • 0

If I create a java Random Access File object against a file. What happens when the file is renamed?

case1. Let’s say, I created a RAF object against test.log. Then I renamed test.log -> test1.log by doing something like

mv test.log test1.log

What happens to my RAF object then in this case?

case2. again, create a RAF object against test.log then:

mv test.log test1.log
touch test.log

in this case, is my object pointing to test.log or test1.log

case3. what if my RAF object is pointing to a log file which will be rotated eventually?

Most importantly, can someone explain to me what happens under the cover? like how the RAF object points/refers to the actual file, how it works when file is renamed or deleted.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T10:13:27+00:00Added an answer on June 4, 2026 at 10:13 am

    ===========================

    My Own test

    ===========================

        RandomAccessFile rand = new RandomAccessFile("/tmp/test_log", "rw"); 
        System.out.print("file created"); //======lineA======
        while (true) {
            Thread.sleep(8000);
            System.out.print("finish sleeping");
            int i = (int) rand.length(); //=====lineB=====
            rand.seek(0); // Seek to start point of file
            for (int ct = 0; ct < i; ct++) {
                byte b = rand.readByte(); // read byte from the file
                System.out.print((char) b); // convert byte into char
            }
        }
    

    test case 1:

    remove the test_log file after lineA before lineB, it finishes reading the whole file without any problems/Exceptions.

    test case 2:

    mv /tmp/test_log /tmp/test_log.bk after lineA before lineB, again,it finishes reading the whole file without any problems/Exceptions.

    test case 3:

    following test case 2, start writing extra lines to /tmp/test_log.bk,

    echo "test line1 bla bla" >> /tmp/test_log.bk
    echo "test line2 bla bla" >> /tmp/test_log.bk
    

    it reads the whole file now problem, PLUS, it reads the new lines added in test_log.bk as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm trying to create a Random Access file in java. I write something in
I've created a file using java.io.File , FileInputStream & FileOutputStream . Suppose that I
How can I create a random integer n in Java, between 1 and k
How can I create an array of 20 random bytes in Java?
How to create in Android Java a random number between min and max excluding
I am using java.util logging classes to create a rolling file appender. I want
Is there a way to create Java classes @ at runtime (classes methods n
I'm using Apache BCEL to dynamically create java classes that will each have its
I'm new to Java. I want to create Java Array and insert data into
Eclipse and MyEclipse create new Java files with an extra blank line after the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.