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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:26:41+00:00 2026-05-27T19:26:41+00:00

In my Android app I should store the data from user in simple text-file,

  • 0

In my Android app I should store the data from user in simple text-file, that I created in the raw directory. After this, I’m trying to write file in APPEND MODE by using simple code from the Google’s examples:

try 
{
    FileOutputStream fos = openFileOutput(FILE_NAME, Context.MODE_APPEND);
    fos.write((nameArticle+"|"+indexArticle).getBytes());
    fos.close();    
} 
catch (FileNotFoundException e) 
{               
    e.printStackTrace();
} 
catch (IOException e) 
{
    e.printStackTrace();
}

But nothing happens: no exceptions, but I can see nothing in my FILE_NAME, besides the single record, which was added by me.

What am I doing wrong ? Is it possible at common to write to file in emulator ?

  • 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-27T19:26:42+00:00Added an answer on May 27, 2026 at 7:26 pm

    openFileOutput will only allow you to open a private file associated with this Context’s application package for writing. I’m not sure where the file you’re trying to write to is located. I mean full path. You can use the code below to write to a file located anywhere (as long as you have perms). The example is using the external storage, but you should be able to modify it to write anywhere:

    public Uri writeToExternalStoragePublic() {
        final String        filename        = mToolbar.GetTitle() + ".html"; 
        final String        packageName     = this.getPackageName();
        final String        folderpath      = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/" + packageName + "/files/";
        File                folder          = new File(folderpath);
        File                file            = null;
        FileOutputStream    fOut            = null;
    
        try {
            try {
                if (folder != null) {
                    boolean exists = folder.exists();
                    if (!exists) 
                        folder.mkdirs();                    
                    file = new File(folder.toString(), filename);
                    if (file != null) {
                        fOut = new FileOutputStream(file, false);
                        if (fOut != null) {
                            fOut.write(mCurrentReportHtml.getBytes());
                        }
                    }
                }
            } catch (IOException e) {
                Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
            }
            return Uri.fromFile(file);
        } finally {
            if (fOut != null) {
                try {
                    fOut.flush();
                    fOut.close();
                } catch (IOException e) {
                    Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
                }
            }
        }
    }
    

    In the example you have given, try catching ‘I0Exception`, I have a feeling you do not have permission where you are trying to write.

    Have a Happy New Year.

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

Sidebar

Related Questions

i've developed an android app that's fetches an xml file and displays this data
In Android, you can store user's config in preferences file. So where should the
I have a table in my Android app that only should store the 50
I have an Android app that fetches data from the web service using ksoap2,
In my Android app, each activity is filled with data from an xml file
I created a native Android app that basically hosts a webView control. That webView
An Android/Iphone app will be accessing application data from the server. [Django-Python] How can
I am currently loading text into my app from an xml file from server.
Actually i want to know how to store data from my app in the
I have an app in android that in a different thread from the UI(which

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.