Creating and writing file in to /data folder of android device

Hi I need to create and write the text file in to /data directory..

this is the code I am using for this.

  • android MapView in Fragment
  • Android Debug Bridge (adb) device - no permissions
  • DrawerLayout getting stuck on swipe
  • class file for android.support.v4.widget.DrawerLayoutImpl not found on travis support-v4 21.0
  • How to mount the android img file under linux?
  • How to use ArrayAdapter<myClass>
  • try {
        Runtime runtime = Runtime.getRuntime();
        Process process = runtime.exec("chmod 777 /data");
        process.waitFor();
    
        resultFile = new File(Environment.getDataDirectory()
                                + "/resultfile.txt");
        Log.i(TAG,"File Object Created....."+resultFile);
    } catch (Exception e) {
        Log.i(TAG, "Exception in Environment.getDataDirectory()"
                   + e.toString());
    }
    
    try {
        try {
            Runtime runtime = Runtime.getRuntime();
            Process process = runtime.exec("chmod 777 /data/resultfile.txt");
            process.waitFor();
    
            if (!resultFile.exists())
                resultFile.createNewFile();
    
        } catch (IOException ioException) {
            Log.i(TAG, "Exception in creating file..."
                       + ioException.toString());
        }
    
        try {
            if (fileWriter == null)
                fileWriter = new FileWriter(resultFile);
        } catch (FileNotFoundException fileNotFoundException) {
                Log.i(TAG, "FileNotFoundException....."
                           + fileNotFoundException.toString());
        }
    

    but I am getting these below problems…

    Exception in creating file...java.io.IOException: Permission denied
    
    FileNotFoundException.....java.io.FileNotFoundException: /data/resultfile.txt (Permission denied)
    
    Exception  in saveResultsToFile.....java.lang.NullPointerException
    

    plz help me in this… thanks.

    Related posts:

    Remove app from recent apps programmatically
    Mute the global sound in Android
    Android Fragment, going back without recreating/reloading Fragment
    Clarify the Firebase connections
    Android - Forced locale resetted on orientation changes
    Android decoder-&gt;decode returned false for Bitmap download
    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.