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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:44:14+00:00 2026-06-13T13:44:14+00:00

I am trying to write an Android program to accept input and then write

  • 0

I am trying to write an Android program to accept input and then write the data to a file on the internal storage of my phone. When I execute my program on the emulator it makes a file just as I expect it to, but when I try and execute it on my phone the file doesn’t seem to be created. I’ve looked around on this site and I can’t seem to find a solution to my problem anywhere (a few similar ones, but nothing that worked for me) I was hoping you guys might be able to offer me advice on what I’m doing wrong.

FileOutputStream fos = null;
String x = "Sample String";
    try{
            fos = openFileOutput("answers.txt", MODE_PRIVATE);
            fos.write(x.getBytes());

        } catch (IOException e) {
            e.printStackTrace();
        }    

    try {
           fos.close();
         } catch (IOException e) {
            e.printStackTrace();
    }

On the emulator, I can find the file in DDMS at “data/data/com.example.helloandroid/files/answers.txt”. On the phone, if I try to open up the data folder in DDMS it shows it is an empty directory. I have already added in this line to my manifest:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

I cannot seem to think of anything else that I could be doing wrong. Thanks in advance for the help, it is appreciated.

  • 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-13T13:44:16+00:00Added an answer on June 13, 2026 at 1:44 pm

    Your code is fine, but like others have said DDMS in Eclipse does not have the proper access to the internal storage, which is where /data/data lives. You can find a reference to the different types of Android storage at http://developer.android.com/guide/topics/data/data-storage.html

    One way to get access is to root your device.

    Another way is to install a userdebug build.

    The easiest way however is via the undocumented run-as option of adb. This allows you to access files owned by your app, even if they are in internal storage.

    To verify that the file you are interested in is being created, type in at the command line:

    adb shell run-as com.example.helloandroid ls -l /data/data/com.example.helloandroid/files/
    

    To get the contents of a specific file, type in, also at the command line:

    adb shell run-as com.example.helloandroid cat /data/data/com.example.helloandroid/files/answers.txt
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a file to the external storage location on Android.
I am trying to write a file in android using phonegap cordova 1.5.0. Below
Alright, so I'm trying to write a program for Android for a project for
I'm trying to write an Android widget that shows how much data has been
I am trying to write a file in Android. private void writeScoreToFile(BlastScore result) {
I'm trying to write a program for the Android platform where I deal with
I'm Trying to Write Logs to Custom Log.txt File on Android File using this
I am trying to send data from an Android app to a PHP file
I am trying to write to a file in an Android app with this
I'm trying to implement my first android Program. It should write calendar entries (I

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.