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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:21:24+00:00 2026-05-22T21:21:24+00:00

I am having some problems with creating and editing text files. The file never

  • 0

I am having some problems with creating and editing text files. The file never seems to store the data.

  • I need to create a text file, if one
    is not available.
  • If there is data in the file, read that data and make it available.
  • The data stored is a String comprising of three integer values, separated by a , Eg: String finalWrite = "3,5,1"
  • So this string needs to be split up, and converted into integers to allow for addition of new counters.
  • Those new counters need to be written into the text file stored on the device

There are no errors occurring, and no force closures.

I was only able to figure out that the values are not being stored properly, using Logcat.

I have reviewed documentation on the Android development site. If anyone can help or point me in the right direction, it would be much appreciated!

The write method that I am using:

public void WriteItIn() throws IOException
{
    FileOutputStream fOut = openFileOutput("stats.txt", Context.MODE_WORLD_READABLE);
    OutputStreamWriter osw = new OutputStreamWriter(fOut);
    ReadItIn(); //calls the read method, to get the values from the file
    int tmp1 = 0 + countertmp + counter;
    int tmp2 = 0 + counterpostmp + counterpos;
    int tmp3 = 0 + counternegtmp + counterneg;
    finalwrite = "" + tmp1 + "," + tmp2 + "," + tmp3;
    osw.write(finalwrite);
    osw.flush();
    osw.close();
}

The Read method:

public void ReadItIn() throws IOException
            {
                FileInputStream fIn = openFileInput("stats.txt");
                InputStreamReader isr = new InputStreamReader(fIn);
                char[] inputBuffer = new char[fIn.available()];
                isr.read(inputBuffer);
                stringFromFile = new String(inputBuffer);
                String [] tmp = stringFromFile.split("\\,");
                if(tmp.length > 0)
                {
                    Log.d("READ", " NOT NULL");
                    for(int i = 0;i<tmp.length ; i++)
                    {
                        String temper = tmp[i];
                        if(temper == null || temper == "")
                        {
                                Log.d("NULL", "NULLIFIED");
                        }
                        else
                            try
                        {
                            int x = Integer.parseInt(temper, 10);
                            if(i == 0){counter = x;}
                            else if(i == 1){counterpos = x;}
                            else if(i == 2){counterneg = x;}
                        }
                        catch(NumberFormatException e)
                        {
                            e.printStackTrace();
                        }
                    }   
                }
                else
                    Log.d("READ", "NULL");
            }
  • 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-22T21:21:24+00:00Added an answer on May 22, 2026 at 9:21 pm

    The main problem is that as soon as you invoke openFileOutput, your stats.txt file gets erased every time again and again.

    If you try to debug step by step your code, you can see that the first time you run the application, the file gets created with 0 size when you invoke openFileOutput. You can check this from the DDMS File explorer.

    So when you read it it holds nothing, and nothing is read by ReadItIn. And when you write and close it, you can see from the DDMS File explorer that the file exists and has size > 0, rightly so.

    But when you pass again by WriteItIn, as soon as you invoke openFileOutput, you can see from File explorer that the file size goes back to 0.

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

Sidebar

Related Questions

I am having some problems creating custom types for my data table, using jquery.datatables.js.
Having some problems with creating regular expression with subpatterns on php. Need some help.
I seem to be having some problems creating a jquery plugin. I am testing
I am having some problems creating a query that gives me the average of
I'm having some problems creating a view for a node within my website. The
I'm creating a messaging web app in ASP.NET and are having some problems when
I am having some problems creating a loop that could show the cheapest price.
I'm having some problems with creating pagination with a HABTM relationship. First, the tables
I have some large files (images and video) which I need to store in
Im having some problems creating a custom search form for jqGrid, on the last

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.