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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:15:48+00:00 2026-06-04T07:15:48+00:00

I am creating a little app that will let a user read what’s in

  • 0

I am creating a little app that will let a user read what’s in a certain textfile in /data/local, edit it, and then save it.
I have gotten everything to work by using some tutorials here and there, but there’s still something not working.

Root access has been achieved, and writing/reading the file is done too, but when pressing the “Write” button, I get a toast saying “open failed: EACCES (Permission denied)”. Google unfortunately didn’t help me much on this one.
Also, I am using the WRITE_TO_EXTERNAL_STORAGE permission.

Code:

package bas.sie.datadatafix;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.actionbarsherlock.app.SherlockActivity;

public class DataFixActivity extends SherlockActivity {

    EditText txtData;
    Button btnReadSDFile;
    Button btnWriteSDFile;
    Button btnReadSkipFile;
    Button btnWriteSkipFile;
    Button btnClearScreen;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Process p;  
        try {  
           // Preform su to get root privledges  
           p = Runtime.getRuntime().exec("su");   

           // Attempt to write a file to a root-only  
           DataOutputStream os = new DataOutputStream(p.getOutputStream());  
           os.writeBytes("echo \"Do I have root?\" >/system/sd/temporary.txt\n");  

           // Close the terminal  
           os.writeBytes("exit\n");  
           os.flush();  
           try {  
              p.waitFor();  
                   if (p.exitValue() != 255) {  
                      // TODO Code to run on success  
                      Toast.makeText(this, "root", Toast.LENGTH_LONG);  
                   }  
                   else {  
                       // TODO Code to run on unsuccessful  
                       Toast.makeText(this, "No root", Toast.LENGTH_LONG);
                   }  
           } catch (InterruptedException e) {  
              // TODO Code to run in interrupted exception  
               Toast.makeText(this, "No root", Toast.LENGTH_LONG);  
           }  
        } catch (IOException e) {  
           // TODO Code to run in input/output exception  
            Toast.makeText(this, "NO root", Toast.LENGTH_LONG);  
        }  

        if(!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())){
            Toast.makeText(this, "External SD card not mounted", Toast.LENGTH_LONG).show();
        }

        txtData = (EditText) findViewById(R.id.txtData);

        btnReadSDFile = (Button) findViewById(R.id.btnReadSDFile);
        btnReadSDFile.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                // write on SD card file data in the text box
                try {
                    File myFile = new File("/data/local/move_cache.txt");
                    FileInputStream fIn = new FileInputStream(myFile);
                    BufferedReader myReader = new BufferedReader(
                            new InputStreamReader(fIn));
                    String aDataRow = "";
                    String aBuffer = "";
                    while ((aDataRow = myReader.readLine()) != null) {
                        aBuffer += aDataRow + "\n";
                    }
                    txtData.setText(aBuffer);
                    myReader.close();
                    Toast.makeText(getBaseContext(),
                            "Done reading from SD: 'move_cache.txt'",
                            Toast.LENGTH_SHORT).show();
                } catch (Exception e) {
                    Toast.makeText(getBaseContext(), e.getMessage(),
                            Toast.LENGTH_SHORT).show();
                }
            }
        }); 

        btnWriteSDFile = (Button) findViewById(R.id.btnWriteSDFile);
        btnWriteSDFile.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                // write on SD card file data in the text box
                try {
                    File myFile = new File("/data/local/move_cache.txt");
                    myFile.createNewFile();
                    FileOutputStream fOut = new FileOutputStream(myFile);
                    OutputStreamWriter myOutWriter = new OutputStreamWriter(
                            fOut);
                    myOutWriter.append(txtData.getText());
                    myOutWriter.close();
                    fOut.close();
                    Toast.makeText(getBaseContext(),
                            "Done writing to SD: 'move_cache.txt'",
                            Toast.LENGTH_SHORT).show();
                } catch (Exception e) {
                    Toast.makeText(getBaseContext(), e.getMessage(),
                            Toast.LENGTH_SHORT).show();
                }
            }
        }); 

        btnReadSkipFile = (Button) findViewById(R.id.btnReadSkipFile);
        btnReadSkipFile.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                // write on SD card file data in the text box
                try {
                    File myFile = new File("/data/local/skip_apps.txt");
                    FileInputStream fIn = new FileInputStream(myFile);
                    BufferedReader myReader = new BufferedReader(
                            new InputStreamReader(fIn));
                    String aDataRow = "";
                    String aBuffer = "";
                    while ((aDataRow = myReader.readLine()) != null) {
                        aBuffer += aDataRow + "\n";
                    }
                    txtData.setText(aBuffer);
                    myReader.close();
                    Toast.makeText(getBaseContext(),
                            "Done reading from SD: 'skip_apps.txt'",
                            Toast.LENGTH_SHORT).show();
                } catch (Exception e) {
                    Toast.makeText(getBaseContext(), e.getMessage(),
                            Toast.LENGTH_SHORT).show();
                }
            }
        }); 

        btnWriteSkipFile = (Button) findViewById(R.id.btnWriteSkipFile);
        btnWriteSkipFile.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                // write on SD card file data in the text box
                try {
                    File myFile = new File("/data/local/skip_apps.txt");
                    myFile.createNewFile();
                    FileOutputStream fOut = new FileOutputStream(myFile);
                    OutputStreamWriter myOutWriter = new OutputStreamWriter(
                            fOut);
                    myOutWriter.append(txtData.getText());
                    myOutWriter.close();
                    fOut.close();
                    Toast.makeText(getBaseContext(),
                            "Done writing to SD: 'skip_apps.txt'",
                            Toast.LENGTH_SHORT).show();
                } catch (Exception e) {
                    Toast.makeText(getBaseContext(), e.getMessage(),
                            Toast.LENGTH_SHORT).show();
                }
            }
        }); 

        btnClearScreen = (Button) findViewById(R.id.btnClearScreen);
        btnClearScreen.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                // clear text box
                txtData.setText("");
            }
        }); 


    }// onCreate

}

Thanks in advance,

Bas

  • 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-04T07:15:49+00:00Added an answer on June 4, 2026 at 7:15 am

    Try this logic for writing and reading the file on local storage, and just a remainder, though i know u did it, but still..use WRITE_TO_EXTERNAL_STORAGE permission.

    For Reading from a file

    File f = new File("my.txt");
    FileReader fr = new FileReader(f);
    BufferedReader br  = new BufferedReader(fr);
    
    String s = null;
    
    while ((br=readLine())!=null) {
    
    // Do whatever u want to do with the content of the file,eg print it on console using SysOut...etc
    
    }
    
    br.close();
    

    For Writing to a file:

    Boolean isDone = true;
    Scanner scan = new Scanner(System.in);
    File f = new File("my.txt");
    FileWriter fr = new FileWriter(f);
    BufferedWriter br  = new BufferedWriter(fr);
    
    while (b) {
    
       if (!b) {
    
     br.write(new Scanner(System.in).nextLine());
    
     }
    
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a browser based QC/data entry app that will let people edit OCRed
I'm new to Core Data. I'm creating an app that will allow a user
I'm creating a little app that configures a connected device and then saves the
I'm creating (really, re-creating) an app that has existing user and other data in
I'm creating a little web app to play videos. Data about the videos will
I'm creating a layout for an iPad app that will consist of xx number
I currently am working on a little app that requests user info from my
I've been wondering how to do this for ages. I'm creating a little app,
I am creating a little script that allows me to slide my content sections
I'm creating a little paint app, and I want to give my painters the

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.