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 8853519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:40:29+00:00 2026-06-14T13:40:29+00:00

Trying to read a log file line-by-line (in Java). This log file is being

  • 0

Trying to read a log file line-by-line (in Java). This log file is being written to simultaneously by another process (non-java program).

I have 2 approaches:

  1. BufferedReader
    • BufferedReader br = new BufferedReader(new FileReader(logFile));)
  2. RandomAccessFile
    • RandomAccessFile accessFile = new RandomAccessFile(logFile.getAbsolutePath(), "r");

Do both these approaches cause the file to be locked untill I call the close method on the BufferedReader/RandomAccessFile object?

Are there any other ways in Java to read a file in such a way that the file is not locked/blocked for other processes/programs?

PS: In all my searches, I have come across multiple answers/solutions (old and new) to this problem. I just wish to seek clarification/closure on this issue.

  • 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-14T13:40:30+00:00Added an answer on June 14, 2026 at 1:40 pm

    BufferedReader is preferable to RandomAccessFile on performance grounds, but neither of them will lock the file at all unless the operating system kindly does so for you, in which case closing the file will release it.

    However the operating system may also kindly prevent you reading the file at all if someone else is writing to it.

    Reading a sequential file while another process is writing to it is not good design. You shouldn’t really be reading log files at all. Log files are for humans. You should be using a database.

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

Sidebar

Related Questions

I am trying to read data from a .log file and process its contents.
I'm trying to process a log file, each line of which looks something like
I'm trying to read a log file of log4net: FileStream fs = new FileStream(filePath,
I am trying to read in an XML file that I have saved to
In Perl I am trying to read a log file and will print only
I'm trying to find a nice way to read a log file in real
I am trying to read the log files or any other file and display
I am currently trying to read in a log file that consists of [content].
I have a log file which has single strings on each line. I am
I am trying to design Log File Parser for my application. I have thousands

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.