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

  • SEARCH
  • Home
  • 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 7990551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:02:59+00:00 2026-06-04T13:02:59+00:00

I only want to discuss about this in java/linux context. RandomAccessFile rand = new

  • 0

I only want to discuss about this in java/linux context.

RandomAccessFile rand = new RandomAccessFile("test.log", "r");

VS

File file = new File("test.log");

After the creation, we start reading the file to the end.

  1. In java.io.File case, it will throw IOException when reading the file if you mv or delete the physical file prior to the file reading.

    public void readIOFile() throws IOException, InterruptedException {
        File file = new File("/tmp/test.log");
        System.out.print("file created"); // convert byte into char
        Thread.sleep(5000);
        while (true) {
            char[] buffer = new char[1024];
            FileReader fr = new FileReader(file);
            fr.read(buffer);
            System.out.println(buffer);
        }
    }
    
  2. But in RandomFileAccess case, if you mv or delete the physical file prior to the file reading, it will finish reading the file without errors/exceptions.

    public void readRAF() throws IOException, InterruptedException {
        File file = new File("/tmp/test.log");
        RandomAccessFile rand = new RandomAccessFile(file, "rw");
        System.out.println("file created"); // convert byte into char
        while (true) {
            System.out.println(file.lastModified());
            System.out.println(file.length());
            Thread.sleep(5000);
            System.out.println("finish sleeping");
            int i = (int) rand.length();
            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
        }
    }
    

    }

Can anyone explain to me why ? Is there anything to do with file’s inode?

  • 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-04T13:03:00+00:00Added an answer on June 4, 2026 at 1:03 pm

    The OS based file system services such as creating folders, files, verifying the permissions, changing file names etc., are provided by the java.io.File class.

    The java.io.RandomAccessFile class provides random access to the records that are stored in a data file. Using this class, reading and writing , manipulations to the data can be done. One more flexibility is that it can read and write primitive data types, which helps in structured approach in handling data files.

    Unlike the input and output stream classes in java.io, RandomAccessFile is used for both reading and writing files. RandomAccessFile does not inherit from InputStream or OutputStream. It implements the DataInput and DataOutput interfaces.

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

Sidebar

Related Questions

I only want log4net to keep let's say 10 days-worth of log files as
I only want this function to run if .toolbar li does not have the
So I only want this JavaScript to be included in the response to the
I have a css file that I only want to be visible to Firefox
This is not a how to question. I want to discuss two possible ways
I only want to reboot when uninstalling. This is a fragment from my WiX
I only want a simple Splash Screen Example. Get the Code, Insert my picture,
We only want one instance of our app running at any one time. So
I only want a method to activate if the pixel that is clicked is
If I only want to check if something is impossible or not (i.e., I

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.