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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:18:07+00:00 2026-05-30T15:18:07+00:00

I am currently saving a message to a single file from multiple activity classes

  • 0

I am currently saving a message to a single file from multiple activity classes within my app. Each activity class has the same function WriteToFile.

public void WriteToFile(String info) {

    FileOutputStream FoutS = null;
    OutputStreamWriter outSW = null;

    try {

        FoutS = openFileOutput("file.txt", MODE_PRIVATE);
        outSW = new OutputStreamWriter(FoutS);
        outSW.write(info);
        outSW.flush();
    }

    catch (Exception e) {
    }

    finally {
        try {
            outSW.close();
            FoutS.close();
        } catch (IOException e) {
        }
    }
}

I have been attempting to create a separate class which holds this function write (and read) to file but I haven’t been able to without getting errors.

I think the function needs to have context passed through to the WriteToFile void like…

    //Changes to this line
 public void WriteToFile(String info, Context context) {

    FileOutputStream FoutS = null;
    OutputStreamWriter outSW = null;

    try {
                      //Changes to this line
        FoutS = context.openFileOutput("file.txt", MODE_PRIVATE);
        outSW = new OutputStreamWriter(FoutS);
        outSW.write(info);
        outSW.flush();
    }

    catch (Exception e) {
    }

    finally {
        try {
            outSW.close();
            FoutS.close();
        } catch (IOException e) {
        }
    }
}

if that is correct am I passing the context correctly?

String msg = "This is a message";

WriteToFile(msg, this);

It’s not working so I am doing something wrong.

  • 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-30T15:18:09+00:00Added an answer on May 30, 2026 at 3:18 pm

    You should use your context to call the method

     context.openFileOutput("file.txt", context.MODE_PRIVATE);
    

    what you wrote has no meaning, or far from what you mean.

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

Sidebar

Related Questions

I'm trying to get my head around saving to multiple models from the one
I am currently saving a .net ( c# ) usercontrol to the disk as
Currently we are saving files (PDF, DOC) into the database as BLOB fields. I
I'm using EntLib v4 for Logging and currently I'm saving the events to the
currently i'm trying to use imagick to generate some images without saving them on
Currently I'm doing some unit tests which are executed from bash. Unit tests are
I have an app that is saving to a db (using Entity Framework) and
We are currently enhancing an ASP.NET app that performs quotes on a number of
How can one optimize the database structure that currently has two tables tbl_incoming and
In my app I save an XML file to the user's SD card by

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.