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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:01:45+00:00 2026-06-05T09:01:45+00:00

I used following method to write data to a file in one android application

  • 0

I used following method to write data to a file in one android application

 private void writeFileToInternalStorage() {

    String eol = System.getProperty("line.separator");
    BufferedWriter writer = null;

 try{
    writer = new BufferedWriter(new OutputStreamWriter(openFileOutput("myFile.txt", MODE_WORLD_WRITEABLE|MODE_WORLD_READABLE)));
      writer.write("Hello world!");
    } 
    catch (Exception e) 
    {
        e.printStackTrace();
    } 
    finally 
    {
      if (writer != null) 
      {
        try 
        {
            writer.close();
        } 
        catch (IOException e) 
        {
            e.printStackTrace();
        }
      }
    }
}

Then I tried to read that file from another android application using this method

 private void readFileFromInternalStorage(){
    String eol = System.getProperty("line.separator");
    BufferedReader input = null;
    try 
    {
        input = new BufferedReader(new InputStreamReader(openFileInput("myFile1.txt")));
         String line;
        StringBuffer buffer = new StringBuffer();
        while ((line = input.readLine()) != null) 
        {
            buffer.append(line + eol);


        }

       TextView tv = (TextView) findViewById(R.id.textView);  
        tv.setText(buffer.toString().trim());

    } 
    catch (Exception e) 
    {
        e.printStackTrace();
    } 
    finally 
    {
        if (input != null) 
        {
            try 
            {
                input.close();
            } 
            catch (IOException e) 
            {
                e.printStackTrace();
            }
        }
    }
}

Second method can’t read the file. I added read write permissions also, but it shows only blank screen. What can be the error and how can I correct that ??. I’m new to Android programming and need your help.

Thanks!

  • 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-05T09:01:48+00:00Added an answer on June 5, 2026 at 9:01 am

    The problem is

    openFileOutput("myFile.txt", MODE_WORLD_WRITEABLE|MODE_WORLD_READABLE))
    

    The documentation says:

    This file is written to a path relative to your app within the

    So the case is you are writing file in path relative to application 1 and trying to read it from
    path relative to application 2.

    You should be able to call Environment.getExternalStorageDirectory() to get the root path to the SD card and use that to create a FileOutputStream. From there, just use the standard java.io routines.

    Look below snippet to write file to SD card.

    private void writeToSDCard() {
    
    
    try
            {
                File file = new File(Environment.getExternalStorageDirectory(),
                        "filename");
                BufferedWriter writer = new BufferedWriter(new FileWriter(file));
                writer.write("Hello World");
                writer.close();
            } catch (IOException e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    }
    

    Look below snippet to read file saved on SD card.

    private void readFileFromSDCard() {
        File directory = Environment.getExternalStorageDirectory();
        // Assumes that a file article.rss is available on the SD card
        File file = new File(directory + "/article.rss");
        if (!file.exists()) {
            throw new RuntimeException("File not found");
        }
        Log.e("Testing", "Starting to read");
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new FileReader(file));
            StringBuilder builder = new StringBuilder();
            String line;
            while ((line = reader.readLine()) != null) {
                builder.append(line);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have used the follwing function to write data to user application folder private
According to Javadocs, when I used javax.sound.sampledTargetDataLine 's following method: public void open(AudioFormat format,int
I've got following classes: public class Container { private String name; private Data data;
i have used following code in my c# application string verification_url = @http://site.com/posttest.php?; string
I used following documentation to write a method in Vala to send key press
I have the following method (used to generate friendly error messages in unit tests):
How come when I use the following method, to be used to convert all
Can I use a native method which returns a pointer? I used the following
In my application, I am using an AsyncTask to write some data to a
The following code is from the Facebook Android SDK, and is used for all

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.