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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:08:14+00:00 2026-05-24T18:08:14+00:00

I am creating a file in my application and I am keep on writing

  • 0

I am creating a file in my application and I am keep on writing some content in to this file.

But after my file reaches to some size, let say 100 lines, I want to erase the first line and write the new line to the bottom.

The requirement is my file should be limited, but it should maintain the latest content that I have written in to file.

Please let me know if its possible in Java? Please let me know if there’s any alternative to do this.

  • 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-05-24T18:08:15+00:00Added an answer on May 24, 2026 at 6:08 pm

    Please let me know if its possible in Java?

    This can’t be done in a simple way. You can only truncate the last part of a file. (This is an inherit limit from the underlying file system, and due to the same reasons as to why you can’t insert bytes in the middle of a file.)

    You can do it manually by:

    1. Figuring out the byte-length, n, of the first line.
    2. For i = n ... length of file
      1. Write byte at pos i to pos i - n
    3. Truncate the file to length length of file - n.

    Please let me know if there’s any alternative to do this.

    I suggest you solve it using a cyclic buffer or something similar. Still though, you’d get into trouble if not all lines are equally long, unless you keep the buffer in memory, and dump it to (a cleared) file.

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

Sidebar

Related Questions

I'm creating a xml-file for display in Excel using _di_IXMLDocument. But for some tags
From the iPhone Programming Guide When creating files or writing out file data, keep
Im creating a application that writes strings to a plist file, but the problem
I am creating a file-oriented database of some test results performed by various users.
When creating a new file with vim, I would like to automatically add some
What should a web programmer keep in his mind while creating a web application
I am creating a Generate Report button for some data in my application. The
I'm creating a web application that will involve habitual file uploading and retrieval (PDFs,
I'm creating a file manager in VB.NET. I included some icons in the project
I am creating a file-sharing application I want to integrate into a windows shell.

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.