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

The Archive Base Latest Questions

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

I am creating one text file which will connected to some server. this text

  • 0

I am creating one text file which will connected to some server.
this text file will receive its contents from the server.
It will receive the some text data continuously.

To limit the file size , I am checking no.of lines in the file and if exceeds the mark I am clearing file content. Server will write from the beginning.

Below is the code I have used to do this :

LineNumberReader myReader = new LineNumberReader( new FileReader(new File("mnt/sdcard/abc.txt")));
while(true) {   

    while(myReader.readLine() != null) {
        counter ++;
    }

    if(counter > 100 ) {

        PrintWriter writer = new PrintWriter("/mnt/sdcard/abc.txt");
                    writer.print("");
                    writer.close();
                    writer = null;
        counter = 0;
    }

}

But after I clear the contents in a file my “counter” not increasing.
But my file is having some data.
I think after reading done I have set my “myReader” to some intial..?
If its how to set that to initial so that .readLine() should start from begining.

  • 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-24T20:14:44+00:00Added an answer on May 24, 2026 at 8:14 pm
    • Shouldn’t you close myReader before writing to the file??

    LineNumberReader myReader = new LineNumberReader( new FileReader(new File("mnt/sdcard/abc.txt")));
    while(true)
    {   
        while(myReader.readLine() != null) {
            counter++;
        }
    
        if(counter > 100 )
        {
            //CLOSE myReader
            myReader.close();
            PrintWriter writer = new PrintWriter("/mnt/sdcard/abc.txt");
            writer.print("");
            writer.close();
            writer = null;
            counter = 0;
            //REOPEN myReader
            myReader = new LineNumberReader( new FileReader(new File("mnt/sdcard/abc.txt")));
        }
    }
    

    • Shouldn’t you make sure that changes to the file done by the server and changes to the file done by this loop are synchronized??
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating an application, which has to get some data from text files. The
I am creating one jsp page in which I read in a text file,
I'm creating a PHP script that imports some data from text files into a
HI All I am creating a log file for our website which will log
I am creating a web interface to enable a user import data from text
I'm looking for some pros and cons of creating one operation per wdsl against
I am creating a Generate Report button for some data in my application. The
I am creating an app which will be used to upload images to a
I'm creating a file-browser in ASP.Net but I have run into a problem which
I'm creating an HTML file containing a table with alternating row colors. One of

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.