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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:55:35+00:00 2026-06-11T01:55:35+00:00

So the Title pretty much sums up my problem, but I’m not sure what

  • 0

So the Title pretty much sums up my problem, but I’m not sure what I’m doing wrong as far as code goes.

Here’s the snipbit where I write to the file:

                try {

                    FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
                    OutputStreamWriter osw = new OutputStreamWriter(fos);

                    osw.append(assignmentTitle + "\n" + assignmentDate + "\n");
                    osw.flush();
                    osw.close();

                } catch (FileNotFoundException e) {
                    //catch errors opening file
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }

Edit: This is where I read from the file every time the activity is called

private void readDataFromFile() {
        try {
            //Opens a file based on the file name stored in FILENAME.
            FileInputStream myIn = openFileInput(FILENAME);

            //Initializes readers to read the file.
            InputStreamReader inputReader = new InputStreamReader(myIn);
            BufferedReader BR = new BufferedReader(inputReader);

            //Holds a line from the text file.
            String line;

            //currentAssignment to add to the list
            Assignment currentAssignment = new Assignment();

                while ((line = BR.readLine()) != null) {
                    switch (index) {
                    case 0:
                        //Toast.makeText(this, line, Toast.LENGTH_LONG).show();
                        currentAssignment.setTitle(line);
                        index++;
                        break;
                    case 1:
                        //Toast.makeText(this, Integer.toString(assignmentListIndex), Toast.LENGTH_LONG).show();
                        currentAssignment.setDate_due(line);
                        Statics.assignmentList.add(assignmentListIndex, currentAssignment);
                        index = 0;
                        assignmentListIndex++;
                        currentAssignment = new Assignment();
                        break;
                    default:
                        Toast.makeText(this, "error has occured", Toast.LENGTH_SHORT).show();
                        break;
                    }
                }
                BR.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
    }

Thats in a function when the user clicks on create a new assignment. When they click the save button on the assignment, it’s supposed to save that assignment to a file and then I read it later and display it in a listView. What it’s doing is displaying the first item in the listView and when I create a new assignment, it’s overwriting the previous text in save file and replacing it in the listView. If you guys need me to post more code Let me know. I’m so confused as to why this isn’t working 🙁

  • 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-11T01:55:37+00:00Added an answer on June 11, 2026 at 1:55 am

    Instead of Context.MODE_PRIVATE, use Context.MODE_APPEND. This mode appends to an existing file instead of erasing it. (More detail on those in the openFileOutput docs.)

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

Sidebar

Related Questions

The title pretty much sums it up but I was wondering why systems like
The title pretty much says it but here is some background: I have an
Title pretty much sums it up. The external style sheet has the following code:
The title pretty much sums it up, and I'm sure there's a perfectly valid
Well the title Question pretty much sums it up, But I'd like to detail
Title pretty much sums it up. Is there a technical name given to a
The title pretty much sums up my question. When is it more efficient to
The title pretty much sums it up: How can I get the server IP
Question in title pretty much sums it up. I have some resource object defined
Well the title pretty much sums the question. The only thing I found is

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.